[SOLVED] Adding to a QGridLayout the way Creator can.
-
Hi
In Creator you can add widgets to a QGridLayout
and it can add / remove Columns doing so.So If have w1 w2 w3
I can drag between a widget w2 and w3 to get
w1 w2 MyNew w3How can I do this from code / dynamic ? (seems not to be possible)
Thevoid QGridLayout::addWidget(QWidget * widget, int row, int column, Qt::Alignment alignment = 0)
Will replace what ever widget already in row, column, not make room for new one.
Thank you
-
Hi,
Just put the widget on the row/column you want:
QGridLayout *layout = new QGridLayout; layout->addWidget(new QPushButton(tr("Test1")), 0, 0); layout->addWidget(new QPushButton(tr("Test2")), 1, 1); layout->addWidget(new QPushButton(tr("Test3")), 2, 2);
-
@SGaist
well I want to (later) insert a new one between Test1 and Test2. (imagine they are on same row)
Like I can in Creator.
Is that possible ?It seems to replace any widget there.not add an extra.
-
Indeed, it seems that a replace + add combo is the only way
-
@SGaist
Hi, ok, i kinda fear that it would not work that way.
Im going to try to use a widget with a layout to fake a row instead. -
QHorizontalLayout + QVerticalLayout ?
You can also check the sources of designer to see how it's done there
-
@SGaist
I actually tried to use the source (luke) but I could simply not spot the files where such
drag and drop would happen. Grep didn't help me this time :(