Tuesday, 30 August 2016

pyqgis - Buttons (Ok, Cancel) disappearing in "Apri Modulo" from Attribute Table in QGIS



QGIS 2.0 has changed the visualisation of a form opened from the attribute table: instead of opening the form in a separate window, the form is opened in the same one. This is not a problem, but all the buttons disappear...


I created my own form with Qt4 and all the logic with PyQt and the majority of the constraints are associated to the Ok button: now my logic is no longer useful.


Is it possible to re-enable these buttons in QGIS 2.0.1?


I copy here part of my code, maybe someone can help me.



from PyQt4.QtCore import *  
from PyQt4.QtGui import *
from definizioni import *

myDialog = None
denominazione = None
denominazioneCheck = None

def formOpen(dialog,layerid,featureid):
global myDialog

myDialog = dialog

global denominazione, denominazioneCheck
denominazione = myDialog.findChild(QLineEdit,"denominazione")
denominazione.textChanged.connect(denominazione_onTextChanged)
if (denominazione.text() == "NULL"):
denominazione.setText("")
else:
temp = denominazione.text()
denominazione.setText("null")

denominazione.setText(temp)

buttonBox = myDialog.findChild(QDialogButtonBox,"buttonBox")
# Disconnect the signal that QGIS has wired up for the dialog to the button box.
buttonBox.accepted.disconnect(myDialog.accept)
# Wire up our own signals.
buttonBox.accepted.connect(validate)
buttonBox.rejected.connect(myDialog.reject)
self.connect(buttonBox, SIGNAL("accepted()"), self.accept)


def denominazione_onTextChanged(text):
global denominazioneCheck

if not validateStringNotNull(text):
denominazione.setStyleSheet("background-color: rgba(255, 107, 107, 150);")
denominazioneCheck = -2
else:
if not validateAlpha(text):
denominazione.setStyleSheet("background-color: rgba(255, 107, 107, 150);")
denominazioneCheck = -1

else:
denominazione.setStyleSheet("")
denominazioneCheck = 1

# Valido la form
def validate():
if denominazioneCheck == -2:
messageBoxErrore(myDialog,"La denominazione di un comune non puo' essere vuota")
else:
if denominazioneCheck == -1:

messageBoxErrore(myDialog,"La denominazione di un comune non puo' contenere numeri")
else:
# Return the form as accepted to QGIS.
myDialog.accept()

I need that the field of the form respect some constraints, as you can see.


In case that constraints are not fulfilled I don't want that the record is stored in the database (I don't want accept() signal is called!).




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...