Search code examples
pythonpyqt4qwidget

Python Pyqt Widget Not Displaying Correctly


I'm having a problem opening a pyqt widget popup from a main window. The widget is opening within the main window. The buttons, text, and boxes seem to get mixed in the main window and not opening as a separate window/widget.

I can post a picture later if needed.

Here's some of the code, hopefully only the important parts;

class MainWindow(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.tableWidget.doubleClicked.connect(self.open_item_widget)

    def open_item_widget(self):
        self.item_widget = ItemWidget(self)
        self.item_widget.show()


class ItemWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_itemWidget()
        self.ui.setupUi(self)
        self.ui.cancelOkButtonBox.rejected.connect(self.close)
        self.ui.cancelOkButtonBox.accepted.connect(self.submit_changes)

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    mainwindow = MainWindow()
    mainwindow.show()
    sys.exit(app.exec_())

Thank you for all your help.


Solution

  • Correct code:

    self.item_widget = ItemWidget()
    

    The error in line:

    self.item_widget = ItemWidget(self)