PDA

View Full Version : Modify QDockWidget title background when in focus



ronno
23rd January 2011, 00:48
I have two QDockWidgets:

// Create the two dockable widgets.
QDockWidget *a_dock = new QDockWidget(tr("abc"));
QDockWidget *b_dock = new QDockWidget(tr("xyz"));

// Add widgets to above dockables...

// Add the two dockable widgets created above.
addDockWidget( Qt::LeftDockWidgetArea, a_dock );
addDockWidget( Qt::BottomDockWidgetArea, b_dock );

Is there a way to have the corresponding QDockWidgets' title bar to become highlighted when the embedded widgets are in focus?

bothorsen
23rd January 2011, 08:35
Not directly. You could try experimenting with setting a new stylesheet on the two dock widgets depending on the focus. See http://doc.qt.nokia.com/4.7-snapshot/stylesheet-examples.html#customizing-qdockwidget on css for dock widgets.

Alternatively, you might have to do your own QStyle subclass and let it check the focus flag on painting the dock.

d_stranz
23rd January 2011, 16:29
I think he'll have to do a QStyle subclass. Setting stylesheet properties won't override the default behavior difference between docked and floating. I looked at this yesterday when considering the question, and I didn't see any simple property changes that would have the desired effect.

Maybe an easier approach might be to just draw a highlight border rect around the whole dock widget when docked and with focus. Subclass QDockWidget, and in the paint event, let the widget draw itself first, then check the focus and docked status. If both are true, then draw a rect in highlight color around the widget.

Not exactly the same thing as highlighting the title bar, but the purpose is to indicate to the user that the widget has focus.

A different question is determining how the dock widget gets focus without the user having to click on it. You may need to handle mouseEnter and mouseLeave events in addition to the paint event.