[SOLVED] QGridLayout: different % widths



  • Hey, I currently have a qgridlayout like:

    Row 1: QHBoxLayout( Widget - Widget - Widget )
    Row 2: QHBoxLayout( Widget - Widget - Widget )
    Row 3: QHBoxLayout( Widget - Widget - QVBoxLayout(QLabel - QLCDNumber))

    Now all these layouts and the widgets inside them have the same size.
    So for row 1: 33.33% / 33.33% / 33.33%
    What I would like: 25% / 50% / 25% for all rows.

    Is this possible?

    Thank you!

    edit:
    I tried doing this with the middle widget:
    middleWidgetRow1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
    This gets me : 1% / 98% / 1%.

    edit: Got it working with horizontal stretch!


  • Lifetime Qt Champion

    Hi,

    You should get what you want using the stretch factor:
    @
    hBoxLayout->addWidget(widget1, 1);
    hBoxLayout->addWidget(widget2, 2);
    hBoxLayout->addWidget(widget3, 1);
    @

    Hope it helps



  • Ha, that's a smaller solution than the one I'm using. Thanks for that!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.