【问题标题】:QPushButton no longer responding inside GroupBoxQPushButton 在 GroupBox 内不再响应
【发布时间】:2014-09-10 23:31:59
【问题描述】:

创建一个带有一堆按钮和标签的 QGroupBox 也是如此。一切正常,现在突然按钮无法点击。事实上,组框内的任何内容都不可点击。有任何想法吗?我一直在拔头发,想看看哪里出错了。

已简化代码并对其进行了测试。没有错误只是不能点击按钮。我想知道这是不是育儿问题?

import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class PxJob(QWidget):

    def __init__(self, parent, geo, title):
        super(PxJob, self).__init__(parent)

        frame = QGroupBox(parent)
        frame.setGeometry(geo)
        frame.setTitle(title)
        grid = QGridLayout()
        frame.setLayout(grid)
        butt = QPushButton('test')
        butt.setCheckable(True)
        grid.addWidget(butt)


class PxManager(QMainWindow):

    def __init__(self, *args):
        super(PxManager, self).__init__()
        self.initUI()

    def initUI(self):

        # Main Layout
        job = PxJob(self, QRect(10,60,830,120), 'Shot 02')
        col = QVBoxLayout()
        col.addWidget(job)

        window = QWidget()
        window.setLayout(col)
        self.setCentralWidget(window)


        self.setGeometry(300, 300, 850, 200)
        self.setWindowTitle('Manager')
        self.show() 

def main():

    app = QApplication(sys.argv)
    ruc = PxManager()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

【问题讨论】:

  • 好的...现在已修复。我应该实例化 QGroupBox,而不是实例化 QWidget。现在工作:)。但是总是热衷于学习其他方式和更多。因此,请随时发表评论。

标签: python button pyqt pyqt4 clickable


【解决方案1】:

您需要在PxJob中的__init__末尾添加此行:

self.setLayout(grid)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-09
    • 1970-01-01
    • 2012-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多