[Qt-interest] Nested widget disappears when I add a spacer item / dynamically adding widgets to widgets
Malyushytsky, Alex
alex at wai.com
Wed May 26 23:33:35 CEST 2010
There is nothing special in your code to be called "dynamic".
99% of the widgets in Qt application are allocated with operator new and you don't add widget to widget.
Remember that correctly asked question is half of the answer.
My advice is to start with QtDesigner to construct the final widget layout the way you want.
Then check the code how it does it, make minimal required modifications, write equivalent to that code if you don't want to use designer generated for some reason.
This way you minimize possibility of problem occur. Also it is a good way to learn how to create complex widgets manually.
Also if you would like someone to debug or review your code, creating compliable example yourself might help a lot.
There are probably people who like creating files and project, and do it themselves to test your code, but I would do it unless I am interested in the problem myself.
At the same I would not mind to help, if I see that person made a reasonable effort to either solve the problem himself or is trying to minimize time I need to spend to be able at least to reproduce the problem.
If your time is valuable for you, and you don't feel is valuable for somebody, why would you bother spend it to help such person?
Try to do what you can to minimize time they need to help you and your chances to get help are rising.
As for your current problem if I am not mistaken in my assumptions without trying the code you are missing something like :
this->setLayout(gLayout);
Regards,
Allex
P.S. >> " Related to my unanswered question yesterday ..."
If I were you and were looking for help on the mailing list, I would avoid
using phrases like above.
Are people paid or other way obligated to answer you?
Also keep in mind that some people might have weekly digests delivered and have not even had a chance to read what you posted yesterday yet.
-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Kustaa Nyholm
Sent: Wednesday, May 26, 2010 2:13 AM
To: QT Interest List
Subject: [Qt-interest] Nested widget disappears when I add a spacer item / dynamically adding widgets to widgets
Related to my unanswered question yesterday here is a more specific
test case:
I've got following simple code:
gLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
QWidget* top=new QWidget();
new QPushButton("A",top);
gLayout->addWidget(top);
gLayout->addWidget(new QPushButton("B"));
This works, and displays two buttons, A and B.
But if I add a spacer to the mix by adding a single line:
gLayout->addItem(
new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
then button A disappers!
What is going on?
Note that button A is a child of the widget 'top' which is what I add
to the layout. If I add A button to gLayout directly then there is no
problem but inmy bigger application that is not feasible because 'top' is a
form maintained with Qt Designer...
So what is the proper way to add a widget that contains widgets
to a layout?
br Kusti
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.
“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”
“Please consider our environment before printing this email.”
More information about the Qt-interest-old
mailing list