"Sticky option" for widget based window
-
I try to implement a sticky = always-on-top option for a "homebrew" window, based on a QWidget created without parent. The widow is created and controlled from a normal QMainWindow-derived application.
window=new QWidget(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint);The window looks and works as expected. It contains a sticky-checkbox, which toggles the WindowStaysOnTopHint:
void DlgSceneView::stayOnTopSl(bool enabled) { window->setWindowFlag(Qt::WindowStaysOnTopHint, enabled); }Strange behavior: The widow "vanishes" (hides?) as soon as I toggle this flag, BUT when I show the window again (through a user action from the main application), it works. I can turn the sticky behabior on and off.
So I tried to include the show action directly in the event slot:void DlgSceneView::stayOnTopSl(bool enabled) { window->setWindowFlag(Qt::WindowStaysOnTopHint, enabled); window->show(); }This does show the window as expected but suddenly the sticky behavior is permanently lost, it always follows normal stacking order.
Qt 5.15.2 on Ubuntu 20.04.5 LTS with "standard" GNOME.
Does anyone have an idea why- The widow hides at all
- The show command preservers the sticky behavior if show is call from the message queue of the QMainWindow but not if called from within the windows own queue?
Many thanks!