I have a QGIS plugin for displaying feature data and I'm trying to make a custom dialog to prompt the user to change the id of the feature being saved if the id is already in use.

For some reason the QDialog that works perfectly well in a standalone script returns blank when rendered in QGIS. In the following picture you can see both dialogs, the one on the right is the dialog from the standalone script, the one on the left is from QGIS:

enter image description here

The code for both dialogs is the same:

class NewIdDialogue(QDialog):
    def __init__(self, old_id='', parent=None):
        super(NewIdDialogue, self).__init__(parent)
        self.old_id = old_id

        layout = QVBoxLayout(self)

        self.line_edit = QLineEdit(self.old_id)

        # OK and Cancel buttons
        buttons = QDialogButtonBox(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
            QtCore.Qt.Horizontal, self)

    def get_text(self):
        return self.line_edit.text()

    def getNewID(old_id, parent=None):
        dialog = NewIdDialogue(old_id=old_id, parent=parent)
        result = dialog.exec_()
        new_id = dialog.get_text()
        return new_id, result == QDialog.Accepted

The reason why I tried this with a custom QDialog is that the call to the standard QDialog returns a blank dialog with no height, here at least the dialogs are the same size, but all the internal elements are missing.

Any suggestions on how to fix this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.