Python QPushButton不再在GroupBox内响应
创建一个QGroupBox,其中包含一系列按钮和标签。一切都很好,现在突然按钮不可点击了。事实上,groupbox中没有任何内容是可点击的。有什么想法吗?我一直在竭尽全力想看看我哪里出了错 我们简化了代码并对其进行了测试。没有错误,只是不能点击按钮。我想知道这是否是一个为人父母的问题Python QPushButton不再在GroupBox内响应,python,button,pyqt,pyqt4,clickable,Python,Button,Pyqt,Pyqt4,Clickable,创建一个QGroupBox,其中包含一系列按钮和标签。一切都很好,现在突然按钮不可点击了。事实上,groupbox中没有任何内容是可点击的。有什么想法吗?我一直在竭尽全力想看看我哪里出了错 我们简化了代码并对其进行了测试。没有错误,只是不能点击按钮。我想知道这是否是一个为人父母的问题 import sys from PyQt4.QtGui import * from PyQt4.QtCore import * class PxJob(QWidget): def __init__(se
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()
您需要在
PxJob
中的\uuuu init\uuuu
末尾添加此行:
self.setLayout(grid)
好的,现在修好了。我不应该实例化QWidget,而应该实例化QGroupBox。现在工作:)。然而,我们总是渴望学习其他方法和更多。所以请随意评论。