[Qt-interest] Nested widget disappears when I add a spacer item / dynamically adding widgets to widgets
Kustaa Nyholm
Kustaa.Nyholm at planmeca.com
Thu May 27 10:09:03 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.
You are of course correct about that at the technical level. However my
web research before I posted showed that a lot of people used this
misconception to describe pretty much the same problem I was experiencing,
hence I felt that it would be appropriate. Maybe it was a bad tactical move.
> Remember that correctly asked question is half of the answer.
Yeah, goes without saying, I'm no new newbie to programming nor mailing
lists.
>
> 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.
That is sound advice but is not directly applicable to what I was doing. As
you saw from my second (non working) code snippet I had just two buttons and
a spacer, but in an arrangement that would no created by QtDesigner (it
seldom creates non working code!).
I actually cracked the issue by experimenting with my second simple example,
simplifying it until it worked (just two buttons!) and the putting things
back until it failed and pinpointing the exact issue.
>
> This way you minimize possibility of problem occur. Also it is a good way to
> learn how to create complex widgets manually.
>
Again good advice, but this was hardly a complex layout and my intention was
quite the opposite: to create all the layouts with QtDesigner and then
just switch 'dynamically' what is displayed.
What was strange was that this worked, until I added a trivial spacer!
> Also if you would like someone to debug or review your code, creating
> compliable example yourself might help a lot.
True, but I was not asking nor hoping anyone actually review to code but
spell the beans because this is not the first time this issue came up.
Many people out there know the issue and the solution.
> 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.
Sure, I completely agree.
> 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?
I probably missed the logic of that sentence but I sure hope I did not gave
the impression that I expected / demanded an answer or that people use
their valuable time to solve my problems.
>
> Try to do what you can to minimize time they need to help you and your chances
> to get help are rising.
That's why kept working on my problem (and had been working on it for a day
already before I mailed) and created the second example.
>
> 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);
>
Actually the problem was that if I add a widget hierarchy that does
not have a layout to an other widget and then add a spacer then the
first hierarchy disappears. Once I added (in QtDesigner) a layout to
the widget that I was 'dynamically' adding to my container widget then
adding a space worked as expected.
> 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.
>
Well, I added that phrase to just to avoid annoying people!
I was trying to convey a humble attitude of a guy who has done his homework
and was just trying to provide some additional information. Having got the
impression that this list seems a bit touchy (compared to most Java lists
where I lurk) I felt that without some preamble like that I would get the
kind of "you should not ask twice within 24 hours or don't double post"
response that some people seem to get hit with.
Reminds me of some of the good old alt.comp news groups in the usenet days.
> Are people paid or other way obligated to answer you?
I don't think I deserved that.
> 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.
>
I know there are annoying students who don't bother to do their homework
on every list and just expect the answers be handed to them when they
can't be bothered to google for them, but please give the rest of us some
credit,I've read that response too many times in the few weeks I've lurked
on this list.
with best regards Kusti
More information about the Qt-interest-old
mailing list