Dock button on Menu bar



  • I have an application with multiple QDockWidget, and I want to add the possibility to dock the widget back to his default area. Right now I am using a button inside the window, but I want to use a button on the menu bar, where close|minimize|maximize are usually located. Is it possible to add custom buttons on the menu bar of QDockWidget? If not, I want to use the build-in "Restore" windows button , but I don't seems to find any way to enable it via Qt::WindowFlags.

    Thanks



  • Do you mean the titlebar of the QDockWidget and not the menubar? If so, then you can set a custom titlebar to the QDockWidget using "setTitleBarWidget()":http://doc.qt.nokia.com/latest/qdockwidget.html#setTitleBarWidget and add your buttons to that titlebar. Does that give you what you need?



  • I meant the title bar. I tried what you said and yes it allows to set customs bars. The only issue now is that I am lazy :) and I don't want to recreate the default title bar on my own just to add a button. I also guess it is privately implemented, So I can extract the private implementation and just add the buttons I need. Do you know where is it located??



  • My guess - I did not check - would be that you should be able to use QStyle to draw the title bar. The source where the QDockWindow title bar is drawn should be easy enough to find on your own.



  • The titlebar is indeed privately implemented when the QDockWidget is docked. When the dockwidget is floating, it is using the native titlebar as documented "here":http://doc.qt.nokia.com/latest/qdockwidget.html#setTitleBarWidget

    You have no control over the native titlebar, so you can't modify the titlebar when the dockwidget is floating. If you need to do so, then you need to create a custom titlebar.

    If you only need to modify the titlebar when the QDockWidget is docked however, you can try modifying it using the style as Andre suggested.



  • Ok I am going to design a widget for my title bar. In the first place I wanted to be able to dock a floating Dockwidget with a simple click.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.