Results 1 to 3 of 3

Thread: Modify QDockWidget title background when in focus

  1. #1
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Modify QDockWidget title background when in focus

    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?

  2. #2
    Join Date
    Mar 2008
    Location
    Marslev, Denmark
    Posts
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Modify QDockWidget title background when in focus

    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...ng-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.
    Bo Thorsen, Viking Software
    Qt applications on Linux and Windows

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,315
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Modify QDockWidget title background when in focus

    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.

Similar Threads

  1. QDockWidget-title
    By moowy in forum Qt Programming
    Replies: 18
    Last Post: 23rd April 2014, 20:13
  2. how to hide the title bar when a QDockWidget is docked?
    By oscar721 in forum Qt Programming
    Replies: 5
    Last Post: 23rd January 2014, 20:16
  3. Replies: 0
    Last Post: 13th October 2010, 13:57
  4. Combined Title and Tab for QDockWidget
    By chaoticbob in forum Qt Programming
    Replies: 0
    Last Post: 25th May 2010, 19:16
  5. contextmenu in QDockWidget title
    By klipko in forum Newbie
    Replies: 4
    Last Post: 7th March 2008, 22:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.