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. In QTVerticalLayout How to remove spaces from widgets?
Forum Updated to NodeBB v4.3 + New Features

In QTVerticalLayout How to remove spaces from widgets?

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 2 Posters 961 Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    How did you remove the space ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    Q 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      How did you remove the space ?

      Q Offline
      Q Offline
      qt_emp
      wrote on last edited by
      #3

      @SGaist No, I cannot remove it.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        That was not my question. In any cas take a look at setContentsMargins

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Q 1 Reply Last reply
        2
        • SGaistS SGaist

          That was not my question. In any cas take a look at setContentsMargins

          Q Offline
          Q Offline
          qt_emp
          wrote on last edited by qt_emp
          #5

          @SGaist I implemented the following:

          ui->verticalLayout->setSpacing(0);
          ui->verticalLayout->setMargin(0);
          ui->verticalLayout->setContentsMargins(0,0,0,0);

          This had no effect on the appearance of the buttons within the verticalLayout. The buttons were still evenly spaced.

          I am using Qt4.8 QtCreator 2.8.1 RedHat Enterprise 6.8

          Could this be a bug in 4.8??

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            That's normal. If you want to have them all pushed up against each other on the top, you have to add a stretch after the last bottom with a value higher that the one used for the buttons. If you didn't set the stretch for the buttons (which is usually the case) then a stretch of one is enough. You can also use a QSpacerItem.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            Q 1 Reply Last reply
            2
            • SGaistS SGaist

              That's normal. If you want to have them all pushed up against each other on the top, you have to add a stretch after the last bottom with a value higher that the one used for the buttons. If you didn't set the stretch for the buttons (which is usually the case) then a stretch of one is enough. You can also use a QSpacerItem.

              Q Offline
              Q Offline
              qt_emp
              wrote on last edited by qt_emp
              #7

              @SGaist I tried a stretch(1) shown commented out in my code below. I then implemented the spacerItem and put it into the layout via addItem()........
              This seems to pile all the buttons on top of one another in the upper left corner of the mainWindow:

              QPushButton *pushButton_1 = new QPushButton(this);
              QPushButton *pushButton_2 = new QPushButton(this);
              QPushButton *pushButton_3 = new QPushButton(this);
              QPushButton *pushButton_4 = new QPushButton(this);
              QPushButton *pushButton_5 = new QPushButton(this);
              QPushButton *pushButton_6 = new QPushButton(this);
              QSpacerItem *spc = new QSpacerItem(20,20,QSizePolicy::Expanding,QSizePolicy::Expanding);

              pushButton_1->setText("One");
              pushButton_2->setText("Two");
              pushButton_3->setText("Three");
              pushButton_4->setText("Four");
              pushButton_5->setText("Five");
              pushButton_6->setText("Six");
              
              QVBoxLayout *pLayout = new QVBoxLayout(this);
              
              
              pLayout->addWidget(pushButton_1, 0, Qt::AlignTop);
              pLayout->addWidget(pushButton_2, 0, Qt::AlignTop);
              pLayout->addWidget(pushButton_3, 0, Qt::AlignTop);
              pLayout->addWidget(pushButton_4, 0, Qt::AlignTop);
              pLayout->addWidget(pushButton_5, 0, Qt::AlignTop);
              pLayout->addWidget(pushButton_6, 0, Qt::AlignTop);
              //pLayout->addStretch(1);
              pLayout->addItem(spc);
              setLayout(pLayout);
              

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #8

                Can you show the result with your original code and the spacer item ?

                By the way, are you locked to Qt 4 ? It has reached end of life a long time ago.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                Q 2 Replies Last reply
                0
                • SGaistS SGaist

                  Can you show the result with your original code and the spacer item ?

                  By the way, are you locked to Qt 4 ? It has reached end of life a long time ago.

                  Q Offline
                  Q Offline
                  qt_emp
                  wrote on last edited by
                  #9

                  @SGaist For the foreseeable future, Yes I am stuck with 4.8. Later version has not been cleared through security protocols.

                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Can you show the result with your original code and the spacer item ?

                    By the way, are you locked to Qt 4 ? It has reached end of life a long time ago.

                    Q Offline
                    Q Offline
                    qt_emp
                    wrote on last edited by
                    #10

                    @SGaist I tried on my original post to include a .png of my gui but was unable to post it.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      You can use an image sharing site like imgur.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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