QGridlayout problems



  • 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.



  • 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?



  • 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..



  • 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!


  • Moderators

    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.



  • 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!


  • Moderators

    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



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



  • 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.



  • 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.



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.