Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Widget Overlays

How do I overlay widgets in Qt?

I want to create some widgets and place them out-of-layout, but rather tweak their size and position when some other widget's geometry is changed.

Something like the buttons on the screenshot:

alt text

like image 967
Andrew T Avatar asked Oct 25 '09 17:10

Andrew T


1 Answers

You just need to create your QPushButton (or any QWidget), indicate its parent QWidget and then display it.

Don't add it to the parent layout else you will not be able to move it as you want.

Don't forget to indicate its parent else it will be displayed as independant QWidget.

In these conditions your QPushButton will be considered as child of the QWidget but not member of the parent's layout. So it will be a "floating" child and you must manage it's behaviour when resizing parent's QWidget.

If you want a unified behaviour for all overlay buttons, you should subclass QLayout and redefine members bahaviour.

like image 66
Patrice Bernassola Avatar answered Sep 17 '22 14:09

Patrice Bernassola