Results 1 to 6 of 6

Thread: QTreeWidget + Transparent Selection

  1. #1
    Join Date
    Jul 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QTreeWidget + Transparent Selection

    Hi, I'm a new member. I've been trying to figure this one out of a while. I'm using Qt4.4 and a QTreeWidget/QTreeWidgetItem. Within this widget the items have a different background color based on their state. When I select the items, I want the background color (set in QTreeWidgetItem) to bleed through into the selection color.

    Anyone have any ideas on how to do this?

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreeWidget + Transparent Selection

    One way that works (did that once) is to implement a custom delegate and reimplement paint(): painting the selection background yourself and let the base class paint the rest (remove the QStyle::State_Selected flag).

    HTH

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeWidget + Transparent Selection

    Use style sheets, for example:
    Qt Code:
    1. QTreeView::item:selected {
    2. background: rgba(255, 0, 0, 50%);
    3. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreeWidget + Transparent Selection

    ah, progress

  5. #5
    Join Date
    Oct 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget + Transparent Selection

    Quote Originally Posted by jpn View Post
    Use style sheets, for example:
    Qt Code:
    1. QTreeView::item:selected {
    2. background: rgba(255, 0, 0, 50%);
    3. }
    To copy to clipboard, switch view to plain text mode 
    Does this really work? I have the exact problem and when I tried using stylesheets in this way, the colors are not really blended. Using the alpha factor only results in a lighter shade of the selection color. I'm using qtreeview with a qtablemodel returning the background color for different rows in the table depending on states.

    Right now, I am struggling with my delegate, adding a custom paint-method, but I have to say I feel there should be a simpler way of doing this.

  6. #6
    Join Date
    Oct 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget + Transparent Selection

    I solved the problem by reimplementing paint in my delegate and setting the palette's highlight role to the blended color before calling QItemDelegate:aint(...).

Similar Threads

  1. QTreeWidget selection
    By adhit in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2008, 09:08
  2. Replies: 1
    Last Post: 8th March 2007, 10:12
  3. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32
  4. QTreeWidget & QListWidget different selection
    By munna in forum Qt Programming
    Replies: 9
    Last Post: 21st July 2006, 06:50

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.