Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep widget on top in Qt

Tags:

widget

qt

qt4

I'm creating an application which has a "floating" widget which can be dragged around inside the application window. But it starts up, or tends to go behind other widgets sometimes. Is there any way to make sure that the widget in my application stays on top of all other widgets whenever it is made visible?

Thanks.

like image 444
Anand Avatar asked Mar 17 '10 14:03

Anand


People also ask

What is Qt stacked widget?

QStackedWidget can be used to create a user interface similar to the one provided by QTabWidget. It is a convenience layout widget built on top of the QStackedLayout class. Like QStackedLayout, QStackedWidget can be constructed and populated with a number of child widgets ("pages"):

Should I use Qt Quick or Qt widgets?

Qt Widgets provide means for customization via style sheets, but Qt Quick is a better performing choice for user interfaces that do not aim to look native. Qt Widgets do not scale well for animations. Qt Quick offers a convenient and natural way to implement animations in a declarative manner.

Is Qt widgets deprecated?

It's been so from the beginnings of Qt 5 around 5 years ago. Widgets are not going away anytime soon.


2 Answers

Use the flag Qt::WindowStaysOnTopHint for your QWidget. This will force your widget to stay on top of all other windows

like image 149
Patrice Bernassola Avatar answered Oct 09 '22 20:10

Patrice Bernassola


You can call raise() on your widget to make it appear in front of all other child widgets of the parent it is in. If I read your question correctly, this is the behavior you want. However, any child you create and add to a parent widget will automatically be placed above that widget, so you may need to reraise the widget after additions, or you may want to consider an alternate way of managing the parent/child relationship.

like image 20
Caleb Huitt - cjhuitt Avatar answered Oct 09 '22 19:10

Caleb Huitt - cjhuitt