简体   繁体   中英

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.

Correct code:

self.item_widget = ItemWidget()

The error in line:

self.item_widget = ItemWidget(self)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM