Created
November 4, 2015 14:44
-
-
Save JokerMartini/a4bd6c3df8283e22cc09 to your computer and use it in GitHub Desktop.
Python Pyside: Toggle the expansion of a groupbox in pyside using the groupbox.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PySide import QtGui, QtCore | |
class Example(QtGui.QWidget): | |
def __init__(self,): | |
super(Example, self).__init__() | |
self.initUI() | |
def initUI(self): | |
# formatting | |
self.setGeometry(300, 300, 300, 300) | |
self.setWindowTitle("Example") | |
# widgets | |
self.controlGroup = QtGui.QGroupBox() | |
self.controlGroup.setTitle("Group") | |
self.controlGroup.setCheckable(True) | |
self.controlGroup.setChecked(True) | |
# groupbox layout | |
self.groupLayout = QtGui.QGridLayout(self.controlGroup) | |
self.btn = QtGui.QPushButton("FOO") | |
self.groupLayout.addWidget(self.btn) | |
self.controlGroup.setFixedHeight(self.controlGroup.sizeHint().height()) | |
# signals | |
self.controlGroup.toggled.connect(lambda: self.toggleGroup(self.controlGroup)) | |
# layout | |
self.mainLayout = QtGui.QGridLayout(self) | |
self.mainLayout.addWidget(self.controlGroup) | |
self.show() | |
def toggleGroup(self, ctrl): | |
state = ctrl.isChecked() | |
if state: | |
ctrl.setFixedHeight(ctrl.sizeHint().height()) | |
else: | |
ctrl.setFixedHeight(30) | |
# Main | |
# ------------------------------------------------------------------------------ | |
if __name__ == "__main__": | |
app = QtGui.QApplication(sys.argv) | |
ex = Example() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment