Adding Widgets to widgets
-
Is it possible to add widgets to a widget?
Basically, widgets are added to the layout. I've done so in my coding but it does not give me the desired result.
-
You cant add a widget to a widget directly.
The widget's content is organized in layouts, where you can have multiple sub-widgets.
You can set a widget as parent of another and show it (floating) within parent widget's boundings, but that's not really "adding"
-
@Swati777999 said in Adding Widgets to widgets:
but it does not give me the desired result.
Then please show the code and tell us what your desired result is and what you get...
-
int n=20; QGridLayout *mSDLayout = new QGridLayout(); QMap <int,QWidget*>dTWidgets; QMap <int, QLabel*>Names; QMap <int ,QTableWidget *> dTs; FlowLayout *flowLayout=new FlowLayout(); // Parent Layout for (int ii=0;ii<n;ii++) { dTWidgets[ii] =new QWidget(); // mSDLayout->addWidget(dTWidgets[ii],0,ii); mSDLayout->addWidget(dTWidgets[ii],0,ii,Qt::AlignCenter); Names[ii] =new QLabel(QString("Name %1").arg(ii+1)); flowLayout->addWidget(Names[ii]); flowLayout->setAlignment(Names[ii],Qt::AlignHCenter); dTs[ii] = new QTableWidget(); flowLayout->addWidget(dTs[ii]); dTWidgets[ii]->setLayout(flowLayout);
This gives me following result [with inactive flowLayout functionality]
-
@Swati777999 said in Adding Widgets to widgets:
dTWidgets[ii]->setLayout(flowLayout);
Why?!
Your dTWidgets widgets should be set in flowLayout, not other way around.
Also, why do you use QMap instead of QVector?
-
Sorry to have put it here, this code was meant to be posted for FlowLayout Qs :
For this Q