I am trying to add a QPushButton widget into a QGroupBox such as:
self.btn = QtGui.QPushButton('Push Button')
self.grp_box = QtGui.QGroupBox('Button Section')
self.grp_box.addWidget(self.btn)
When trying to run the code, I got this error : AttributeError: 'NoneType' object has no attribute 'addWidget'
After some online checking, it seems that QGroupBox only allows setLayout
, meaning I will need to use QVBoxLayout
or QHBoxLayout
etc.
Is there anyway to get around this, adding in a widget without the use of any layout(s)? I am using PyQt.
button.move(20, 20)
). However, if the group-box changes size, it could also obscure the button, so you will need to set a minimum size for the group-box, etc, etc. Of course, the whole point of layouts is to avoid having to deal with all these tedious details and allow Qt to manage it all automatically. – Ernaline