PDA

View Full Version : Layout objects reusable?



alitoh
28th April 2011, 15:59
I was wondering if it was possible to use same layout objects (a QHBoxLayout, i.e) to define the layout of different objects.

E.g.




QHBoxLayout * boxLayout;
QGridLayout * gridLayout;

QGroupBox * group1;
QGroupBox * group2;
QGroupBox * group3;

QComboBox * comboBox1;
QComboBox * comboBox2;
QComboBox * comboBox3;

QLabel * label1;
QLabel * label2;
QLabel * label3;

//-------------------

gridLayout->addWidget(label1);
gridLayout->addWidget(comboBox1);

groupBox->setLayout(gridLayout);

and then do somethingl ike gridLayout->clear(); and reuse that layout.

My problem is that I've found myself in need of nested layouts inside 3 GroupBoxes and it would be rather annoying to triple the ammount of objects (once for every GroupBox) just because of it.

Thanks for your help.

AlexSudnik
28th April 2011, 16:51
I think it's possible ,but every time you re-parent your layout to a new widget a previous one will lose it and...become blank.Maybe it's fine if you're gonna have one visible widget at any moment (like with QStackedLayout).