Qt: Keep the child window on top of the parent even when it loses focus

I have a user interface window called in the main window. I would like it to be non-modal, but stay on top of the parent, and if the parent is minimized, it can be minimized.

If the user wants to make changes to both, he should be able to, and the child will not be closed if the user does not close it. The child will always remain on top of the parent, but not on top of everything.

m_child->show(); m_child->activateWindow(); 

The above puts the child on top of the parent, it allows you to work with the parent during the launch of the baby ... but the baby is hidden behind the parent if he loses focus.

 m_child->show(); m_child->activateWindow(); m_child->raise(); 

Without changes.

Using

 Qt::WindowFlags flags = m_child->windowFlags(); m_child->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint); m_child->show(); m_child->activateWindow(); 

The child on top, as I want, I can work with the parent while the child is still displayed on top ... but minimizing the parent also does not minimize the child, and the child remains on top of all windows (it should only be on top of the parent)

How can I create a “toolbar style” effect - have a child above the parent while the parent is active, but minimize children when the parent is minimized?

I also experimented with all the box flags, but they allow the child to hide when he loses focus.

+5
source share
1 answer

You can achieve this by adding the Qt::Tool flag to the toolbar widget and setting the main window as its parent.

See http://doc.qt.io/qt-5/qt.html#WindowType-enum

+9
source

Source: https://habr.com/ru/post/1210773/


All Articles