Creating a form at runtime
-
Hi guys,
I create a form at runtime like the following:
@ QWidget *form=new QWidget(this);
QGridLayout *lay = new QGridLayout();lay->addWidget(new QLabel("Select a User:"), 0, 0); QStringList userlist = db->mpRetrieveUserColumn("username"); userSelectComboBox = new QComboBox(); foreach(QString str, userlist) userSelectComboBox->addItem(str); lay->addWidget(userSelectComboBox, 0, 1, 1, 2); QPushButton *btn = new QPushButton("OK"); connect(btn, SIGNAL(clicked()), this, SLOT(mpOnUserSelected())); lay->addWidget(btn, 2, 2); form->setLayout(lay); form->show();@
I call this in the main thread where I have the ui. However, this show the widget on the existing form. However, I want to have this form like a new modal form on top of the main form. I have been looking into the documentation but couldn't find it yet. Could you please give me a hint?
-
[quote author="MuldeR" date="1398969507"]Try using, e.g., a QDialog instead of QWidget if you want a top-level widget. You could also use QWidget and specify NULL as parent in the constructor.[/quote]
My Lord,
Awesome! I never thought about giving NULL parameter but it make a lot sense. Thanks a lot.