Results 1 to 3 of 3

Thread: How to control the color of the focus rectangle

  1. #1
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Thanks
    7
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default How to control the color of the focus rectangle

    The standard focus rectangle draws as either white or black depending on the background of the widget (from what I can tell anyways)

    In my application I have styled QPushButton via stylesheets to have a gradient background that is very light and requires a black focus rectangle, but Qt is drawing a white focus rectangle! If I change the background color to be solid and the darkest color of my gradient I get the black focus rectangle so I can only assume that gradient background is confusing the painter.

    How can I force it to draw the focus rectangle in black?

    Note that setting the style QPushButton:focus gives a completely different effect it changes the overall look of the button when it has focus and not the focus rectangle itself.

  2. #2
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Thanks
    7
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to control the color of the focus rectangle

    As a follow up, as of 4.7.2 it is not possible to style the focus rectangle yourself, so it should be able to calculate it's color properly when the widget's background is a gradient.

    I reported it as a bug and it can be followed here
    http://bugreports.qt.nokia.com/browse/QTBUG-19406

  3. #3
    Join Date
    Mar 2012
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to control the color of the focus rectangle

    Hi,

    I know it's an old thread, but in case someone wonders in looking for info - you can change focus rectangle using stylesheets. Use option outline.

    if you want your focus rectangle for QPushButton to be black, use style
    Qt Code:
    1. QPushButton { outline: 1px solid #000 }
    To copy to clipboard, switch view to plain text mode 

    oh, btw ... i'm using this in 4.8.2

Similar Threads

  1. Replies: 13
    Last Post: 24th August 2018, 14:29
  2. How can i avoid QPushButton Focus Rectangle
    By nightroad in forum Newbie
    Replies: 8
    Last Post: 4th October 2010, 10:06
  3. Prevent QStyledItemDelegate from drawing focus rectangle
    By stefanadelbert in forum Qt Programming
    Replies: 4
    Last Post: 15th July 2010, 09:43
  4. Hide the focus rectangle of a QGraphicsLineItem
    By ronno in forum Qt Programming
    Replies: 2
    Last Post: 16th June 2009, 10:47
  5. Preventing blue focus rectangle
    By MrGarbage in forum Qt Programming
    Replies: 2
    Last Post: 21st December 2007, 15:36

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.