[Interest] QDockWidgets: how to get regular windows in detached (floating) mode?

René J.V. Bertin rjvbertin at gmail.com
Wed Oct 11 23:36:54 CEST 2017


Hi,

Dock widgets are very useful, but there are cases where I'd like to be able to detach them to a regular window, because

- regular windows stay visible when the application focus changes
- regular windows can do stacking
- regular windows can be put (partly) off the screen

The latter 2 are practical when using a smaller screen size, all three are useful for, say, a documentation browser.

How can one achieve this? I see that QDockWidget::setFloating(true) ultimately just sets the Qt::Tool window flag, so I tried unsetting that. At the moment, I have

    connect(this, &QDockWidget::topLevelChanged, this, [this] (bool floating) {
            if (floating) {
                setTitleBarWidget(0);
                setWindowFlags(Qt::Window);
                updateGeometry();
                activateWindow();
                raise();
            }
        } );

which probably has a number of redundant calls, doesn't handle the case when a QDockWidget is created in "floating" mode and also isn't reliable.

Most of the time, the window simply disappears when the above lambda is triggered. In addition, under X11 the window will have the regular titlebar provided by the WM but looks as if there's a regular window with the floating dock window inside, tiny titlebar included.

What am I missing here?

Thanks,
René



More information about the Interest mailing list