Adding Widgets to widgets
-
wrote on 13 Dec 2021, 02:56 last edited by
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.
-
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.
wrote on 13 Dec 2021, 04:07 last edited byYou 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"
-
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.
@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...
-
@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...
wrote on 13 Dec 2021, 08:56 last edited by Swati777999int 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]
-
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?
-
@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?
wrote on 13 Dec 2021, 09:20 last edited by Swati777999Sorry to have put it here, this code was meant to be posted for FlowLayout Qs :
For this Q
1/6