1

I would like to add a button to QDockWidget's title bar. I know there is a setTitleBarWidget() function but with it I need to rewrite all the style for the title bar. The default style (like "Dock 2" in the picture), with close button, colors, etc, suit me very well. How can I add a button without overriding the default QDockWidget's title bar style ?

QDockWidget's title bar

self.dockWidgetWord.setTitleBarWidget(widgetContainer)

style = ? # is the something I can put here ?
self.dockWidgetWord.setStyle(style)

I also tried to create a widget as child of the one returned by titleBarWidget() but it does not work either.

Tynnor
  • 41
  • 5
  • 2
    You can't. If you want a customized title bar, you have to completely build it on your own. If you want to follow the current style, you need to use the [QStyle](https://doc.qt.io/qt-5/qstyle.html) functions to get the geometries of the buttons and to paint the title (see the various [`SubElement`](https://doc.qt.io/qt-5/qstyle.html#SubElement-enum) enums, like `SE_DockWidgetFloatButton`, etc.). – musicamante Aug 03 '23 at 16:15

0 Answers0