PDA

View Full Version : QTreeWidget + Transparent Selection



Shamwow
19th July 2008, 18:44
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?

caduel
19th July 2008, 20:21
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

jpn
21st July 2008, 17:04
Use style sheets (http://doc.trolltech.com/4.4/stylesheet.html), for example:


QTreeView::item:selected {
background: rgba(255, 0, 0, 50%);
}

caduel
21st July 2008, 17:48
ah, progress ;)

Jennie Bystrom
12th August 2008, 09:27
Use style sheets (http://doc.trolltech.com/4.4/stylesheet.html), for example:


QTreeView::item:selected {
background: rgba(255, 0, 0, 50%);
}


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.

Jennie Bystrom
12th August 2008, 10:23
I solved the problem by reimplementing paint in my delegate and setting the palette's highlight role to the blended color before calling QItemDelegate::paint(...).