Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Bring the Widget Bring to front in Qt?

Tags:

Please have a look at this screenshot:

enter image description here

The circles are custom controls. When I click a control, I need to bring the widget to the front. Ex. if I click the second circle it should look like this:

enter image description here

When the control is clicked I am able to get the sender (i.e. the control). Only thing is how to bring the object to the front.

Please help me fix this issue.

like image 354
saravanan Avatar asked Sep 29 '10 12:09

saravanan


People also ask

How do you overlap widgets in Qt?

Right click on the root widget (easiest in the Object Inspector), and from the bottom of context menu, select Lay out > - Lay out in Grid. Right click on the label, and from Layout alignment > set it aligned to the corner you want.


1 Answers

Have you tried QWidget::raise()?

Raises this widget to the top of the parent widget's stack. After this call the widget will be visually in front of any overlapping sibling widgets.
Note: When using activateWindow(), you can call this function to ensure that the window is stacked on top.

So the pattern I usually use that will ensure a window is shown, brought to the front of sibling widgets and brought in front of other applications is:

widget->show(); widget->activateWindow(); widget->raise(); 
like image 65
the_mandrill Avatar answered Sep 21 '22 07:09

the_mandrill