Minh Tuan Nguyen
Minh Tuan Nguyen

Reputation: 137

Set size for QGroupbox?

I'm new guy, and i start with new simple GUI application, I follow some tutorial on the internet and now i have a trouble with QGroupbox (Pysde). This is my code :

import sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide import QtGui,QtCore

class Form(QtGui.QWidget):

    def __init__(self,parent=None):
        super(Form,self).__init__(parent)

        self.initUi()

    def initUi(self):
        self.setGeometry(300, 300, 800, 600)
        self.setWindowTitle('Library')
        self.setMinimumHeight(600)
        self.setMinimumWidth(800)
        self.setMaximumHeight(600)
        self.setMaximumWidth(1100)

        #Groupbox Show Only
        gpShowonly = QtGui.QGroupBox("Show only :")
        gpShowonly.setGeometry(100,100,200,200)
        chbx1 = QtGui.QCheckBox("x1")
        chbx2 = QtGui.QCheckBox("x2")
        chbx3 = QtGui.QCheckBox("x3")

        serverlayout = QtGui.QHBoxLayout()

        serverlayout.addWidget(chbx1)
        serverlayout.addWidget(chbx2)
        serverlayout.addWidget(chbx3)

        configLayout = QtGui.QVBoxLayout()

        configLayout.addLayout((serverlayout))
        gpShowonly.setLayout(configLayout)

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addWidget(gpShowonly)
        mainLayout.addStretch(1)


        self.setLayout(mainLayout)
        self.show()

app = QApplication.instance()
if app is None:
    app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()

I want it's smaller but it's always full horizontal , I use setGeometry,resize but nothing happen.

Upvotes: 0

Views: 12599

Answers (1)

ekhumoro
ekhumoro

Reputation: 120768

The widgets inside a layout will expand to fill the available space. To prevent this, simply add an expandable spacer to the end of the layout:

    serverlayout = QtGui.QHBoxLayout()
    serverlayout.addWidget(chbx1)
    serverlayout.addWidget(chbx2)
    serverlayout.addWidget(chbx3)
    serverlayout.addStretch()

If this makes the widgets too small, you could give them a minimum width:

    for widget in chbx1, chbx2, chbx3:
        widget.setMinimumWidth(100)

Upvotes: 1

Related Questions