May 27, 2011

luggi luggi
Lab Rat
59 posts

[SOLVED] addWidget determinded

 

Hello

If I add a QWidget in QHBoxLayout. Then it is always added at the end of all other already added QWidgets. Is there a possibility to add a QWidget to a determinded positon, e.g. at the second position?

I’m aware of the possibility to first remove all other QWidgets until the desired position and then add them again after. But this not very flexible if I don’t know how much widgets I have after the second position.

Thx for help.

4 replies

May 27, 2011

Andre Andre
Area 51 Engineer
6031 posts

Sure. Use the insertWidget method instead of the addWidget method.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

May 27, 2011

luggi luggi
Lab Rat
59 posts

Hmmm, sometimes Google isn’t really my friend! : )

May 27, 2011

Andre Andre
Area 51 Engineer
6031 posts

Google is not great for Qt documentation. But the documentation itself is pretty good in general. This is really easy to find. You go to QVBoxLayout, find it pretty much empty of methods, and open op the docs for the super class QBoxLayout instead. A quick glance on that documentation reveals that you have add* methods as well as insert* methods. A pattern that is also available in may other classes dealing with lists or other ordered collections…

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

May 27, 2011

luggi luggi
Lab Rat
59 posts

Jap, that one I’m using too. Normally I should have found this. Don’t know why I haven’t searched for other methods, I was too focused on the addWidget method. Could be friday afternoon. : )

Anyway, I’m very happy with the Qt Community here, thank you very much for this quick help here anytime.

 
  ‹‹ [Solved] Custom Layout plugin for Qt Designer does not work      QGraphicsView transparent over another QGraphicsView ››

You must log in to post a reply. Not a member yet? Register here!