How to assemble and display a dialog box "on the fly"
-
Hi,
I wonder how I can assemble and display a dialog with a QListWidget with items that can be checked with a checkbox (as in options to configure)
So far I've tried this:int scaper::dialogShow(QWidget *parent) { ScaperDialog dialog(parent); dialog.show();
where the
ScaperDialog
class looks like:ScaperDialog::ScaperDialog(QWidget *parent) :QDialog(parent) { list = new QListWidget(parent); item = new QListWidgetItem(); list->setItemWidget(item,new QCheckBox("checkBox")); list->addItem(item); } void ScaperDialog::CheckAll(void){} void ScaperDialog::UncheckAll(void){}
but nothing actiually shows up on invocation of
dialogShow()
what am I missing?
Thanks! -
Hi,
I wonder how I can assemble and display a dialog with a QListWidget with items that can be checked with a checkbox (as in options to configure)
So far I've tried this:int scaper::dialogShow(QWidget *parent) { ScaperDialog dialog(parent); dialog.show();
where the
ScaperDialog
class looks like:ScaperDialog::ScaperDialog(QWidget *parent) :QDialog(parent) { list = new QListWidget(parent); item = new QListWidgetItem(); list->setItemWidget(item,new QCheckBox("checkBox")); list->addItem(item); } void ScaperDialog::CheckAll(void){} void ScaperDialog::UncheckAll(void){}
but nothing actiually shows up on invocation of
dialogShow()
what am I missing?
Thanks!@cerr said in How to assemble and display a dialog with a QListWidget with items that can be checked with a checkbox (as in options to configure):
but nothing actiually shows up on invocation of dialogShow() what am I missing?
You're missing: show() is non blocking call and dialog is a local variable inside dialogShow, so as soon as dialogShow finishes dialog is destroyed. Use exec() instead of show().
-
You're missing: show() is non blocking call and dialog is a local variable inside dialogShow, so as soon as dialogShow finishes dialog is destroyed. Use exec() instead of show().
Okay,
Yes, now the Dialog is showing when I use
dialog.exec();
inscaper::dialogShow()
but it's tiny, i.e. no room to display anything and when I use the mouse to enlarge it, there's no sign of anyQListWidget
, so I set some parameters to resize it:ScaperDialog::ScaperDialog(QWidget *parent) :QDialog(parent) { int nWidth = 300; int nHeight = 300; resize(nWidth, nHeight);
but still no sign of a
QListWidget
, so I gave it a size too, just like:int WidX = 100; int WidY = 100; list = new QListWidget(parent); list->setBaseSize(WidX,WidY);
I still see nothing inside the Dialog....what else am I missing?
Thanks! -
@cerr said in How to assemble and display a dialog box "on the fly":
list = new QListWidget(parent);
Try with
list = new QListWidget(this); -
Hi,
You should put your dialog widgets in a layout. That will enable automatic sizing and positioning.
-
@cerr said in How to assemble and display a dialog box "on the fly":
list = new QListWidget(parent);
Try with
list = new QListWidget(this); -
Hi,
You should put your dialog widgets in a layout. That will enable automatic sizing and positioning.