<tfoot id='3QtNe'></tfoot>

    • <bdo id='3QtNe'></bdo><ul id='3QtNe'></ul>

      <small id='3QtNe'></small><noframes id='3QtNe'>

    1. <legend id='3QtNe'><style id='3QtNe'><dir id='3QtNe'><q id='3QtNe'></q></dir></style></legend>
      <i id='3QtNe'><tr id='3QtNe'><dt id='3QtNe'><q id='3QtNe'><span id='3QtNe'><b id='3QtNe'><form id='3QtNe'><ins id='3QtNe'></ins><ul id='3QtNe'></ul><sub id='3QtNe'></sub></form><legend id='3QtNe'></legend><bdo id='3QtNe'><pre id='3QtNe'><center id='3QtNe'></center></pre></bdo></b><th id='3QtNe'></th></span></q></dt></tr></i><div id='3QtNe'><tfoot id='3QtNe'></tfoot><dl id='3QtNe'><fieldset id='3QtNe'></fieldset></dl></div>

    2. 在按钮按下的滚动区域中加载 QTableWidgets

      时间:2023-08-04

          <tbody id='2WpuM'></tbody>
        1. <i id='2WpuM'><tr id='2WpuM'><dt id='2WpuM'><q id='2WpuM'><span id='2WpuM'><b id='2WpuM'><form id='2WpuM'><ins id='2WpuM'></ins><ul id='2WpuM'></ul><sub id='2WpuM'></sub></form><legend id='2WpuM'></legend><bdo id='2WpuM'><pre id='2WpuM'><center id='2WpuM'></center></pre></bdo></b><th id='2WpuM'></th></span></q></dt></tr></i><div id='2WpuM'><tfoot id='2WpuM'></tfoot><dl id='2WpuM'><fieldset id='2WpuM'></fieldset></dl></div>
        2. <tfoot id='2WpuM'></tfoot>

            <small id='2WpuM'></small><noframes id='2WpuM'>

              <bdo id='2WpuM'></bdo><ul id='2WpuM'></ul>
              <legend id='2WpuM'><style id='2WpuM'><dir id='2WpuM'><q id='2WpuM'></q></dir></style></legend>

                本文介绍了在按钮按下的滚动区域中加载 QTableWidgets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我有一个名为test()"的方法,它将 3 个单行表加载到滚动条中.

                I have a method named 'test()' that loads 3 one-row tables into a scrollbar.

                由于某种原因,我无法弄清楚,但是,如果我只是在加载时激活 test() 它会起作用,但如果我将其注释掉然后尝试通过按下按钮来激活它,它就不起作用.

                For some reason that I cannot figure out, however, the while it works if I simply activate test() on load, it doesn't work if I comment it out and then try to activate it via the push of a button.

                这里是主模块(带有 test())

                Here is the main module (with test())

                from PyQt5 import QtCore, QtWidgets
                from design import Ui_MainWindow
                
                class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
                    def __init__(self, *args, **kwargs):
                        QtWidgets.QMainWindow.__init__(self, *args, **kwargs)
                        self.setupUi(self)
                        #test(self)
                
                def test(self):
                    from random import randint
                    x = randint(0, 99)
                    print(x)
                    height = 30
                    yPos = 0
                    for i in range(3):
                
                        rowVals = ['test%s' % str(x + i)]
                
                        qTbl = QtWidgets.QTableWidget(self.sawDoc)
                        qTbl.setObjectName("tbl%s" % (i))
                        qTbl.setGeometry(QtCore.QRect(0, yPos, 880, height))
                        qTbl.horizontalHeader().setVisible(False)
                        qTbl.verticalHeader().setVisible(False)
                        yPos += height
                
                        qTbl.setRowCount(1)
                        qTbl.setColumnCount(len(rowVals))
                        for r, cell in enumerate(rowVals):
                            item = QtWidgets.QTableWidgetItem()
                            item.setText(str(cell))
                            qTbl.setItem(0, r, item)
                
                if __name__ == "__main__":
                    import sys
                    app = QtWidgets.QApplication(sys.argv)
                    w = MainWindow()
                    w.show()
                    sys.exit(app.exec_())
                

                这里是设计模块(带有按钮)

                And here is the design module (with the button)

                from PyQt5 import QtCore, QtGui, QtWidgets
                
                class Ui_MainWindow(object):
                    def setupUi(self, MainWindow):
                        MainWindow.setObjectName("MainWindow")
                        MainWindow.resize(896, 453)
                        self.centralwidget = QtWidgets.QWidget(MainWindow)
                        self.centralwidget.setObjectName("centralwidget")
                        self.scrDoc = QtWidgets.QScrollArea(self.centralwidget)
                        self.scrDoc.setGeometry(QtCore.QRect(0, 0, 891, 391))
                        self.scrDoc.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
                        self.scrDoc.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
                        self.scrDoc.setWidgetResizable(False)
                        self.scrDoc.setObjectName("scrTest")
                        self.sawDoc = QtWidgets.QWidget()
                        self.sawDoc.setGeometry(QtCore.QRect(0, 0, 869, 300))
                        self.sawDoc.setObjectName("sawDoc")
                        self.scrDoc.setWidget(self.sawDoc)
                        self.btnTest = QtWidgets.QPushButton(self.centralwidget)
                        self.btnTest.setGeometry(QtCore.QRect(430, 400, 80, 15))
                        self.btnTest.setObjectName("btnTest")
                        MainWindow.setCentralWidget(self.centralwidget)
                        self.statusbar = QtWidgets.QStatusBar(MainWindow)
                        self.statusbar.setObjectName("statusbar")
                        MainWindow.setStatusBar(self.statusbar)
                
                        self.retranslateUi(MainWindow)
                        QtCore.QMetaObject.connectSlotsByName(MainWindow)
                
                        self.btnTest.clicked.connect(self.test)
                
                    def test(self):
                        import main
                        main.test(self)
                
                    def retranslateUi(self, MainWindow):
                        _translate = QtCore.QCoreApplication.translate
                        MainWindow.setWindowTitle(_translate("MainWindow", "昊珩のCAT工具"))
                        self.btnTest.setText(_translate("MainWindow", "Test"))
                
                
                
                if __name__ == "__main__":
                    import sys
                    app = QtWidgets.QApplication(sys.argv)
                    MainWindow = QtWidgets.QMainWindow()
                    ui = Ui_MainWindow()
                    ui.setupUi(MainWindow)
                    MainWindow.show()
                    sys.exit(app.exec_())
                

                当我按下按钮时,什么也没有发生(除了打印成功).

                Simply nothing happens when I push the button (except for the print out working successfully).

                谁能告诉我怎么了?

                推荐答案

                一开始是父母给孩子看,之后孩子自己负责展示自己,简单的解决方案是使用show():

                The parents show the children at the beginning, but afterwards it is the responsibility of the children to show themselves, the simple solution is to use show():

                qTbl = QtWidgets.QTableWidget(self.sawDoc)
                qTbl.show()
                

                但是我看到你以一种不优雅的方式实现解决方案,连接在 main.py 中完成,不要修改 Qt Designer 生成的文件(删除 design.py 中的连接和测试方法)您必须使用布局并在其中添加 QTableWidget.

                But I see that you are implementing the solution in an inelegant way, the connection do it in main.py, do not modify the file generated by Qt Designer (delete the connection and the test method in design.py) You must use a layout and there add the QTableWidget.

                class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
                    def __init__(self, *args, **kwargs):
                        QtWidgets.QMainWindow.__init__(self, *args, **kwargs)
                        self.setupUi(self)
                        self.btnTest.clicked.connect(self.test)
                
                    def test(self):
                        from random import randint
                        x = randint(0, 99)
                
                        lay = QtWidgets.QVBoxLayout(self.sawDoc)
                        for i in range(3):
                            rowVals = ['test%s' % str(x + i)]
                            qTbl = QtWidgets.QTableWidget()
                            qTbl.setObjectName("tbl%s" % (i))
                            qTbl.horizontalHeader().hide()
                            qTbl.verticalHeader().hide()
                            qTbl.setRowCount(1)
                            qTbl.setColumnCount(len(rowVals))
                            for r, cell in enumerate(rowVals):
                                item = QtWidgets.QTableWidgetItem()
                                item.setText(str(cell))
                                qTbl.setItem(0, r, item)
                            qTbl.resize(qTbl.sizeHint())
                            lay.addWidget(qTbl)
                

                这篇关于在按钮按下的滚动区域中加载 QTableWidgets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:无法为 pyqt5 gui 应用程序执行脚本 fbs_pyinstaller_ 下一篇:如何使用 PyQt5 运行 while 循环

                相关文章

                最新文章

                    <i id='o8gRH'><tr id='o8gRH'><dt id='o8gRH'><q id='o8gRH'><span id='o8gRH'><b id='o8gRH'><form id='o8gRH'><ins id='o8gRH'></ins><ul id='o8gRH'></ul><sub id='o8gRH'></sub></form><legend id='o8gRH'></legend><bdo id='o8gRH'><pre id='o8gRH'><center id='o8gRH'></center></pre></bdo></b><th id='o8gRH'></th></span></q></dt></tr></i><div id='o8gRH'><tfoot id='o8gRH'></tfoot><dl id='o8gRH'><fieldset id='o8gRH'></fieldset></dl></div>
                    <tfoot id='o8gRH'></tfoot>

                    • <bdo id='o8gRH'></bdo><ul id='o8gRH'></ul>

                    <small id='o8gRH'></small><noframes id='o8gRH'>

                    <legend id='o8gRH'><style id='o8gRH'><dir id='o8gRH'><q id='o8gRH'></q></dir></style></legend>