Skip to content
Advertisement

Create a dependent window?

I want to create a secondary window which is free-floating in relation to the main window. But I also want it to close when the main window closes. Indeed, I want the application to end completely when the main window closes, and assumed this would be default behaviour.

MRE:

JavaScript

As the code is, closing the main window does not close the secondary window.

I thought possibly that making the “master” window the parent of the secondary window might produce this behaviour out of the box, but it appears not: instead the secondary window then gets “incorporated” into the main window.

This is one way to accomplish the specific task:

JavaScript

… but this doesn’t in itself provide a solution to the question of how to make one window dependent on another.

Maybe you have to hard-code it explicitly? I.e. keep tabs on any secondary windows (e.g. in a list) and then explicitly close them when the “master” window experiences closeEvent … ?

Advertisement

Answer

flags Qt::WindowFlags

This enum type is used to specify various window-system properties for the widget. They are fairly unusual but necessary in a few cases. Some of these flags depend on whether the underlying window manager supports them.

Qt::Window
Indicates that the widget is a window, usually with a window system frame and a title bar, irrespective of whether the widget has a parent or not. Note that it is not possible to unset this flag if the widget does not have a parent.

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

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement