views:

83

answers:

1

Hi, i'm working with PyQt4 to make a simple Python GUI app.

The situation is the following:

i have an QMainWindow displaying a central widget and a QDockWidget containing this custom Widget:

class ListTagWidget(QWidget):
        def __init__(self, parent = None):
            super(ListTagWidget, self).__init__()
            addButton = QPushButton("&Add Tag...")
            editButton = QPushButton("&Edit Tag...")
            removeButton = QPushButton("&Delete Tag")
            self.taglist = QListWidget()
            layout = QGridLayout(self)
            layout.addWidget(self.taglist, 1, 1, 1, 1)
            layout.addWidget(addButton, 2, 1)
            layout.addWidget(editButton, 3, 1)
            layout.addWidget(removeButton, 4, 1)
            self.setLayout(layout)
            self.adjustSize()
            #Connections
            self.connect(addButton, SIGNAL("clicked()"), self.addTag)

        def addTag(self):
            dialog = AddTagDlg(self)
            dialog.show()

I basicly want to display this custom dialog class when addButton is clicked:

class AddTagDlg(QDialog):
    def __init__(self, Parent=None):
        super(AddTagDlg, self).__init__()
        buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
        label = QLabel("Tag Name:")
        lineEdit = QLineEdit()
        layout = QGridLayout()
        layout.addWidget(label, 1, 1)
        layout.addWidget(lineEdit, 1, 2)
        layout.addWidget(buttonBox, 2, 1)
        self.setLayout(layout)
        self.setWindowTitle("Add Tag...")

But this don't work. I've managed to create a dialog inline by changing the addTag method to:

def addTag(self):
    dialog = QDialog()
    dialog.show()

But i'm not satisfied with inline dialog creation. What's my error? Thank you.

EDIT

The problem was with the custom dialog class constructor:

class AddTagDlg(QDialog):
    def __init__(self, Parent=None):
        super(AddTagDlg, self).__init__(parent) #<--WAS MISSING
        buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
        ...
A: 

Try calling exec_() on the dialog, this should show you the dialog.

gruszczy
Thanks! I've found that was also necessary to pass super(AddTagDlg, self).__init__(parent) into the custom dialog class. I'll edit my question.
Gianluca Bargelli