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. QT grid layout top left
Forum Updated to NodeBB v4.3 + New Features

QT grid layout top left

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 3.9k 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.
  • D Offline
    D Offline
    DevM
    wrote on 3 Apr 2020, 11:49 last edited by
    #1

    Hey,

    Is there any way to make a grid layout start filling by top-left so that I have something like this (only works because I have filled the grid)
    f4597ceb-93f3-4753-9087-703b5a7ab77f-image.png

    and not this
    b3f67569-cb30-4bab-a2fa-474af657cdad-image.png

    I have seen another answer in which someone created a custom layout but before I go that route I would like to know if there's something I can do in the designer itself.

    J 1 Reply Last reply 3 Apr 2020, 13:59
    0
    • D DevM
      3 Apr 2020, 11:49

      Hey,

      Is there any way to make a grid layout start filling by top-left so that I have something like this (only works because I have filled the grid)
      f4597ceb-93f3-4753-9087-703b5a7ab77f-image.png

      and not this
      b3f67569-cb30-4bab-a2fa-474af657cdad-image.png

      I have seen another answer in which someone created a custom layout but before I go that route I would like to know if there's something I can do in the designer itself.

      J Offline
      J Offline
      JonB
      wrote on 3 Apr 2020, 13:59 last edited by JonB 4 Mar 2020, 18:10
      #2

      @DevM
      Not so far as I know from usage (hence the other person creating a custom layout).

      EDIT I understood your question to be wanting to achieve this in Qt Designer!

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JackTr
        wrote on 3 Apr 2020, 17:38 last edited by JackTr 4 Mar 2020, 17:40
        #3

        I am not sure if I understood you right, but maybe this will help:

           GridLayout->addWidget(pBtn,1,1,1,1,{Qt::AlignTop, Qt::Alignleft});
        
        

        so the button would align in the top left corner.

        In another way you could expand the buttons vertically so they take up the full space of the grid layout depending on its size with something like:

        pBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        
        

        You might wanna fix the size of the QGridLayout widget so it is filled.

        D 1 Reply Last reply 3 Apr 2020, 18:06
        0
        • J JackTr
          3 Apr 2020, 17:38

          I am not sure if I understood you right, but maybe this will help:

             GridLayout->addWidget(pBtn,1,1,1,1,{Qt::AlignTop, Qt::Alignleft});
          
          

          so the button would align in the top left corner.

          In another way you could expand the buttons vertically so they take up the full space of the grid layout depending on its size with something like:

          pBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
          
          

          You might wanna fix the size of the QGridLayout widget so it is filled.

          D Offline
          D Offline
          DevM
          wrote on 3 Apr 2020, 18:06 last edited by
          #4

          @JackTr

          Your solution does somehow help or it gets close enough to what I want
          7a373bb7-cf62-49e4-8fc7-b9619761cf30-image.png

          code doing it:

              this->ui->gridLayout_2->addWidget(uc,1,1,1,1,{Qt::AlignTop,Qt::AlignLeft});
              this->ui->gridLayout_2->addWidget(new UC(this),1,2,{Qt::AlignTop,Qt::AlignLeft});
              this->ui->gridLayout_2->addWidget(new UC(this),1,3,{Qt::AlignTop,Qt::AlignLeft});
              this->ui->gridLayout_2->addWidget(new UC(this),1,4,{Qt::AlignTop,Qt::AlignLeft});
              this->ui->gridLayout_2->addWidget(new UC(this),2,1,{Qt::AlignTop,Qt::AlignLeft});
              this->ui->gridLayout_2->addWidget(new UC(this),2,2,{Qt::AlignTop,Qt::AlignLeft});
          

          Is it possible to change the spacing between those widgets though?

          M 1 Reply Last reply 4 Apr 2020, 06:34
          0
          • D DevM
            3 Apr 2020, 18:06

            @JackTr

            Your solution does somehow help or it gets close enough to what I want
            7a373bb7-cf62-49e4-8fc7-b9619761cf30-image.png

            code doing it:

                this->ui->gridLayout_2->addWidget(uc,1,1,1,1,{Qt::AlignTop,Qt::AlignLeft});
                this->ui->gridLayout_2->addWidget(new UC(this),1,2,{Qt::AlignTop,Qt::AlignLeft});
                this->ui->gridLayout_2->addWidget(new UC(this),1,3,{Qt::AlignTop,Qt::AlignLeft});
                this->ui->gridLayout_2->addWidget(new UC(this),1,4,{Qt::AlignTop,Qt::AlignLeft});
                this->ui->gridLayout_2->addWidget(new UC(this),2,1,{Qt::AlignTop,Qt::AlignLeft});
                this->ui->gridLayout_2->addWidget(new UC(this),2,2,{Qt::AlignTop,Qt::AlignLeft});
            

            Is it possible to change the spacing between those widgets though?

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 4 Apr 2020, 06:34 last edited by mrjj 4 Apr 2020, 06:34
            #5

            @DevM said in QT grid layout top left:

            Is it possible to change the spacing between those widgets though?

            Hi
            Only by making the widgets bigger or the layout area smaller.

            I was wondering if this example layout is close to what you want ?
            https://doc.qt.io/qt-5/qtwidgets-layouts-flowlayout-example.html

            1 Reply Last reply
            0

            1/5

            3 Apr 2020, 11:49

            • Login

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