2014-09-10 100 views
0

所以創建一個帶有一堆按鈕,包含標籤的QGroupBox。一切工作正常,現在突然間按鈕不可點擊。事實上,groupbox內部沒有可點擊的內容。有任何想法嗎?我一直在拉我的頭髮,試圖找出我出錯的地方。QPushButton不再在GroupBox內部響應

簡化了代碼並對其進行了測試。沒有錯誤只是不能點擊按鈕。林想知道如果它的父母問題?

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() 
+0

OK了...現在是固定的。而不是實例化QWidget我應該實例化QGroupBox。現在工作:)。但總是渴望學習其他方式和更多。所以請隨時發表評論。 – Mafster 2014-09-10 23:58:47

回答

1

你需要在__init__末在PxJob加入這一行:

self.setLayout(grid)