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. QGridlayout problems
QtWS25 Last Chance

QGridlayout problems

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 6.7k 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.
  • M Offline
    M Offline
    Mar91
    wrote on last edited by
    #1

    I am trying to use QGridLayout as a grid, where each widget is placed where i want, but this is not possible as each Widget goes where it wants. eg: doing ui->gridLayout->addWidget(remove,1,1,2,2); has no effects, as the widget streches to the entire layout. I only want to assign each widget a fixed position.

    1 Reply Last reply
    0
    • W Offline
      W Offline
      weggi
      wrote on last edited by
      #2

      Are you sure you are using it correctly? Now you define that your widget should be at row 1 in cell 1. You also define columnSpan and rowSpan 2. It means that your widget takes two row cells and two columns cells of the layout.

      Do you have any other widgets in the layout?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mar91
        wrote on last edited by
        #3

        i am a bit confused with QGridlayout, i can't understand if you need another widget near the first one, to don't let the first one eating all the space..

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mar91
          wrote on last edited by
          #4

          Using ui->gridLayout->addWidget(remove,1,1,1,1); places the widget in the center of the QGridlayout, taking all the space. I expected it to took less space!

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koahnig
            wrote on last edited by
            #5

            Do you have several widgets to place in the QGridLayout?
            It reads like you consider the grid positions as coordinates. But that is not the case.

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Mar91
              wrote on last edited by
              #6

              yes, but for example if i want to place a Qpushbutton on the first row (and nothing more), i can't do it, because it streches to fit all the QGridlayout!

              1 Reply Last reply
              0
              • K Offline
                K Offline
                koahnig
                wrote on last edited by
                #7

                well, if you place only one widget, this looks allright.
                See also:
                [quote author="weggi" date="1305487017"]Are you sure you are using it correctly? Now you define that your widget should be at row 1 in cell 1. You also define columnSpan and rowSpan 2. It means that your widget takes two row cells and two columns cells of the layout.

                Do you have any other widgets in the layout?[/quote]

                If you have somewhere in the QGridLayout already several widgets in a row than it should build a grid.
                "Like in the example":http://doc.qt.nokia.com/4.7/qgridlayout.html

                Vote the answer(s) that helped you to solve your issue(s)

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Mar91
                  wrote on last edited by
                  #8

                  As i expected.. so there is no hope on placing it with fixed size..

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    If you want a fixed size single widget, you probably do not want a layout at all. For me it's still unclear, what you want to achieve.

                    The space of a toplevel widget is split between the subwidgets that are put in a layout. As your button is the only widget it gets all the available space. If you have more widgets, the space is split by several rules. You can make some of the subwidgets a fixed size, see the QWidget docs on size policy etc. for some infos.

                    Maybe you should play around with grid layout on a widget in Qt Designer to become comfortable with it's workings.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • W Offline
                      W Offline
                      weggi
                      wrote on last edited by
                      #10

                      Not sure what you are trying to achieve, but you could also try 3x3 grid, button in the middle and "spacers":http://doc.qt.nokia.com/latest/qspaceritem.html#details around the button.

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        giesbert
                        wrote on last edited by
                        #11

                        Perhaps reading the "introduction to layouts":http://doc.qt.nokia.com/4.7/layout.html could also give some insight.

                        Nokia Certified Qt Specialist.
                        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                        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