How to add a maximize button to a floating QDockWidget?

1k views Asked by At

How can I add a maximize button to a floating QDockWidget?

I read about a method with creating a custom titlebar but I would prefer using the standard buttons instead of icons I have to add myself.

The best solution would be if the title bar style wouldn't change when it's made floating.

Dock widget screenshot

1

There are 1 answers

2
alexei On

Initially a floating window will have the following flags: QFlags<Qt::WindowType>(Tool|X11BypassWindowManagerHint|WindowTitleHint|WindowSystemMenuHint|CustomizeWindowHint|WindowCloseButtonHint)

You will need to set the Qt::CustomizeWindowH and add to the other flags on the dock widget the flags Qt:WindowMaximizeButtonHint (or WindowMinMaxButtonsHint) and respectively the Qt:FramelessWindowHint (depending on the system visu you use - need also the X11 flag to set) QFlags<Qt::WindowType>(Tool|X11BypassWindowManagerHint|FramelessWindowHint)

Setting the flag will need to be done using the method setWindowFlags:https://doc.qt.io/qt-5/qwidget.html#windowFlags-prop

Additionally there is another method: setWindowFlag(flag,bool):https://doc.qt.io/qt-5/qwidget.html#setWindowFlag