Search code examples
pythonbuttonpyqtpyqt4clickable

QPushButton no longer responding inside GroupBox


So was creating a QGroupBox with a bunch of buttons, labels contained. Everything was working fine and now all of a sudden the buttons arent clickable. In fact nothing inside the groupbox is clickable. Any ideas? I've been pulling my hair out trying to see where i went wrong.

Have simplified the code down and tested it. No errors just cant click the button. Im wondering if its a parenting issue?

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

Solution

  • You need to add this line at the end of __init__ in PxJob:

    self.setLayout(grid)