简体   繁体   English

Python Pyqt小部件无法正确显示

[英]Python Pyqt Widget Not Displaying Correctly

I'm having a problem opening a pyqt widget popup from a main window. 我在从主窗口打开pyqt小部件弹出窗口时遇到问题。 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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