Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGroupBox not fitted to contents

QGroupBox not fitted to contents

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 348 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stefanoxjx
    wrote on last edited by
    #1

    Hi, I've wrote this code:

        QVBoxLayout *VLayout = new QVBoxLayout(this);
        QHBoxLayout *hlButtons = new QHBoxLayout;
    
        //Tabs
        QGroupBox *groupTabs = new QGroupBox("Tabs");
        QPushButton *btnNewTab = new QPushButton("New Tab");
        QPushButton *btnRenameTab = new QPushButton("Rename Tab");
    
        QVBoxLayout *vlTabs = new QVBoxLayout;
        vlTabs->addWidget(btnNewTab);
        vlTabs->addWidget(btnRenameTab);
        
        vlTabs->addStretch(true);
        hlButtons->addWidget(groupTabs);
        groupTabs->setLayout(vlTabs);
    
        VLayout->addLayout(hlButtons);
    

    but the groupbox is very high compared to the content.
    In the free space I could place another 5 buttons.
    How I can fit GroupBox to content?
    Thanks.

    Regards.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by
      #2

      You can set alignment to it:

          hlButtons->addWidget(groupTabs, 0, Qt::AlignLeft | Qt::AlignTop);
      

      void QBoxLayout::addWidget(QWidget *widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment())

      Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment.
      The stretch factor applies only in the direction of the QBoxLayout, and is relative to the other boxes and widgets in this QBoxLayout. Widgets and boxes with higher stretch factors grow more.
      If the stretch factor is 0 and nothing else in the QBoxLayout has a stretch factor greater than zero, the space is distributed according to the QWidget:sizePolicy() of each widget that's involved.
      The alignment is specified by alignment. The default alignment is 0, which means that the widget fills the entire cell.

      1 Reply Last reply
      1
      • S Offline
        S Offline
        Stefanoxjx
        wrote on last edited by
        #3

        It work fine :)
        Many thanks.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved