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. Adding widget to evenly spaced grid
Forum Updated to NodeBB v4.3 + New Features

Adding widget to evenly spaced grid

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 661 Views
  • 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.
  • E Offline
    E Offline
    EaccB
    wrote on last edited by
    #1

    I need to dynamically add multiple widgets of the same type to a 5x10 grid. The vertical and horizontal distance between each widget should be constant, regardless of how many widgets are currently in the grid. As widgets are added, they will fill a row (left to right) before starting a new row.

    Currently, this doesn't seem possible with QGridLayout as the distance between widgets adjusts. Is my best bet to just use a QFrame and handle the positioning of the widgets myself, which I think will be fairly trivial?

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Add a spacer right and bottom of the grid layout so it shrinks when there are no widgets.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • E Offline
        E Offline
        EaccB
        wrote on last edited by
        #3

        How would I control the spacing between each widget?

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @EaccB said in Adding widget to evenly spaced grid:

          How would I control the spacing between each widget?

          Maybe by taking a look at the documentation? https://doc.qt.io/qt-5/qgridlayout.html#horizontalSpacing-prop

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • E Offline
            E Offline
            EaccB
            wrote on last edited by
            #5

            I've added a vertical and horizontal spacer to the bottom and right side of the grid. As I add widgets, how can I ensure that a widget doesn't overlap a spacer? I.e, there should always be a spacer at the bottom and right - added widgets should be to the top-left of the spacers.

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I don't understand what you mean - when you add a widget to your grid how should it overlap a spacer which is outside of the grid?

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • E Offline
                E Offline
                EaccB
                wrote on last edited by
                #7

                Oh, I thought you meant to add them to the grid. My grid is not enclosed in another layout, so not sure how that would work.

                Christian EhrlicherC 1 Reply Last reply
                0
                • E EaccB

                  Oh, I thought you meant to add them to the grid. My grid is not enclosed in another layout, so not sure how that would work.

                  Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @EaccB You can add spacers in another layout there too.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  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