QGridlayout problems
-
wrote on 15 May 2011, 19:07 last edited by
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.
-
wrote on 15 May 2011, 19:16 last edited by
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?
-
wrote on 15 May 2011, 19:28 last edited by
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..
-
wrote on 15 May 2011, 19:29 last edited by
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!
-
wrote on 15 May 2011, 19:44 last edited by
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. -
wrote on 15 May 2011, 19:46 last edited by
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!
-
wrote on 15 May 2011, 19:54 last edited by
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 -
wrote on 15 May 2011, 19:58 last edited by
As i expected.. so there is no hope on placing it with fixed size..
-
wrote on 15 May 2011, 20:41 last edited by
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.
-
wrote on 15 May 2011, 22:19 last edited by
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.
-
wrote on 16 May 2011, 07:22 last edited by
Perhaps reading the "introduction to layouts":http://doc.qt.nokia.com/4.7/layout.html could also give some insight.
5/11