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. Alignment in groupbox without modifying size policy
Forum Updated to NodeBB v4.3 + New Features

Alignment in groupbox without modifying size policy

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.1k 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by VRonin
    #1

    Imagine I have a QVoxLayout with a QGroupBox and a QTreeView. now inside of the QGroupBox I have another QVBoxLayout with 2 buttons that I want aligned to the top but I still want the QTreeView to take any extra space when resizing. Any suggestions? if I use addStrech or addSpacerItem on the inside layout it will compete with the view for extra space

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    J.HilkJ 1 Reply Last reply
    0
    • VRoninV VRonin

      Imagine I have a QVoxLayout with a QGroupBox and a QTreeView. now inside of the QGroupBox I have another QVBoxLayout with 2 buttons that I want aligned to the top but I still want the QTreeView to take any extra space when resizing. Any suggestions? if I use addStrech or addSpacerItem on the inside layout it will compete with the view for extra space

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      @VRonin mmh, in your Top VBoxLayout, set the SizePoilzy of the GroupBox to 'preferred' give it a stretch factor of 0 and your Treeview of 1. void QBoxLayout::setStretch(int index, int stretch)

      Your QGroupBox should resize to the min-height of your Buttons


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      4
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        I realised I did not provide enough informations in the question so here is a minimal code that shows the problem:

        #include <QWidget>
        #include <QVBoxLayout>
        #include <QTreeView>
        #include <QGridLayout>
        #include <QGroupBox>
        #include <QLabel>
        #include <QPushButton>
        class TestWidget : public QWidget{
            Q_OBJECT
            Q_DISABLE_COPY(TestWidget)
        public:
            explicit TestWidget(QWidget* parent = Q_NULLPTR)
                : QWidget(parent)
            {
                QGridLayout* mainLay = new QGridLayout(this);
                QTreeView* treeView=new QTreeView(this);
                QGroupBox* groupBox1=new QGroupBox(this);
                QVBoxLayout* group1Lay = new QVBoxLayout(groupBox1);
                QPushButton* button1 = new QPushButton("button1",this);
                QPushButton* button2 = new QPushButton("button1",this);
                QGroupBox* groupBox2=new QGroupBox(this);
                QVBoxLayout* group2Lay = new QVBoxLayout(groupBox2);
                group2Lay->addWidget(new QLabel("SpaceTaker",this));
                group2Lay->addWidget(new QLabel("SpaceTaker",this));
                group2Lay->addWidget(new QLabel("SpaceTaker",this));
                group2Lay->addWidget(new QLabel("SpaceTaker",this));
                group2Lay->addWidget(new QLabel("SpaceTaker",this));
                group1Lay->addWidget(button1);
                group1Lay->addWidget(button2);
                group1Lay->addStretch(); // problem
                mainLay->addWidget(groupBox1,0,0);
                mainLay->addWidget(groupBox2,0,1);
                mainLay->addWidget(treeView,1,0,1,2);
            }
        };
        

        @J-Hilk
        I'll try your solution

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        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