Results 1 to 5 of 5

Thread: Prevent QStyledItemDelegate from drawing focus rectangle

  1. #1
    Join Date
    Feb 2010
    Location
    Sydney, Australia
    Posts
    111
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Prevent QStyledItemDelegate from drawing focus rectangle

    I would like to prevent my derived QStyledItemDelegate from painting the focus rectangle.

    I have achieved this before using a QItemDelegate by overriding its drawFocus function and doing nothing.

    However QStyledItemDelegate does not implement drawFocus. Is there another way to prevent the QStyledItemDelegate from not painting the focus rectangle?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Prevent QStyledItemDelegate from drawing focus rectangle

    In the paint function of your custom QStyledItemDelegate class -
    Qt Code:
    1. QStyleOptionViewItem newOption = option;
    2. newOption.state = option.state & (~QStyle::State_HasFocus);
    3. QStyledItemDelegate::paint(painter,newOption,index);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to aamer4yu for this useful post:

    stefanadelbert (15th July 2010)

  4. #3
    Join Date
    Feb 2010
    Location
    Sydney, Australia
    Posts
    111
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Prevent QStyledItemDelegate from drawing focus rectangle

    Beautiful!

    Thanks, aamer4yu.

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Prevent QStyledItemDelegate from drawing focus rectangle

    Hi,

    please also note our search function, because this question is asked every month...

    But why I am replying is, because I wonder what is "better" or if there is a significant difference between
    making a local copy of option as above
    and
    casting the const of option away?

  6. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Prevent QStyledItemDelegate from drawing focus rectangle

    I wonder what is "better" or if there is a significant difference between
    making a local copy of option as above
    and
    casting the const of option away?
    I guess depends on habit too. I usually wont prefer to break something that wasn't meant to be broken.

Similar Threads

  1. Replies: 1
    Last Post: 3rd November 2009, 22:26
  2. Hide the focus rectangle of a QGraphicsLineItem
    By ronno in forum Qt Programming
    Replies: 2
    Last Post: 16th June 2009, 10:47
  3. Drawing a selection rectangle
    By Caius Aérobus in forum Qt Programming
    Replies: 7
    Last Post: 4th April 2009, 15:47
  4. Preventing blue focus rectangle
    By MrGarbage in forum Qt Programming
    Replies: 2
    Last Post: 21st December 2007, 15:36
  5. Replies: 3
    Last Post: 4th June 2007, 09:51

Tags for this Thread

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.