PDA

View Full Version : QGridLayout place new widgets at top



rouge
8th June 2011, 19:46
hi,

how is it possible to add new widgets at top in a grid layout? I like to fill it up dynamic, but after i add the first i would like to at the second at the row 1...

anybody an idea?

greez

Santosh Reddy
8th June 2011, 20:02
Does that mean you don't want to arrange them layout, one over the other?

Create the child widgets with parent (one which contains the layout), and don't add to layout.

rouge
8th June 2011, 21:20
more in detail at the moment i have a list (vector) contains the objects. this list will be grow while the application runs. because i don't want to rearrange all the object in the layout i just add the last one:



vector<Object> list = someObjects;

for (int i = lastCount; i < list.size(); i++){
QLabel *label= new QLabel();
label->setText(list[i]->toString());
lastCount++;
((QGridLayout*) ui.view->layout())->addWidget(label, i, 0);
ui.view->repaint();
}


however i like to arrange them so:

third object
second object
first object

thx

Santosh Reddy
8th June 2011, 22:39
This may not possible with QGridLayout, you need you write a custom Layout Manager.

Oee alternate way which you can try is to create all the QLabels upfront (with null strings), and populate the text, as the applciation gorws. (you should know the number of QLabels upfront). This is not a good practle solution though.

wysota
8th June 2011, 23:02
Have you tried simply adding new widgets to row 0 of the layout?

rouge
21st June 2011, 14:04
Have you tried simply adding new widgets to row 0 of the layout?
Yes i tried this...but its only override the first row...

Rachol
21st June 2011, 14:11
You better use QVBoxLayout, then you can use the insertWidget method

rouge
6th October 2011, 09:06
Thx for the help...the best way i find is to use a QTreeWidget.