[Qgis-developer] python form validation help
Andrew
amcaninch at gmail.com
Mon Oct 10 13:01:54 PDT 2016
I am trying to write some form validation to work around bug #15050
<http://hub.qgis.org/issues/15050>. Based on some examples I have found I
think this should work:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
myDialog = None
notesField = None
def formOpen(dialog,layerid,featureid):
global myDialog
global notesField
myDialog = dialog
notesField = dialog.findChild(QPlainTextEdit,"Notes")
buttonBox = dialog.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)
def validate():
if notesField.document().characterCount() > 1000:
msgBox = QMessageBox()
msgBox.setText("Notes field must be <1000 characters")
msgBox.exec_()
else:
myDialog.accept()
What happens is that I get the message box with the error, but when I click
OK on the message box the form closes and saves anyway and I still lose
text in the multiline field if it exceeds the field length. How do I keep
the form open to allow the user to fix the error(s)?
Thanks,
Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20161010/6b65e635/attachment.html>
More information about the Qgis-developer
mailing list