Wed, 2 Apr 2008 22:59:39 +0100
In modern desktop environments it's common to display a descriptive line of text
below the icon labels in list views and icon views. This text is usually drawn
with a different text color or font weight, and in KDE we implement this feature
by using custom item delegates.
With view items being styleable in Qt 4.4 we'd like to draw the background in
those delegates by using QStyle::drawPrimitive() and PE_PanelItemViewItem,
but as it turns out there are a number of difficulties with doing this.
The main one is that when QStyleOptionViewItem::showDecorationSelected is
false, drawPrimitive() will call subElementRect() with SE_ItemViewItemText to
obtain the rectangle where the selection should be drawn. But when there are
additional text items that subElementRect() is unaware of, this will result in
selection background being drawn in the wrong place.
A possible solution to this problem would be to make it the caller's
to set the rect in the style options to the rectangle where the selection should
be drawn. Another is to add a decoration and a text rectangle to the style
options, to be filled in by the caller. This latter option may be necessary for
the Mac style.
Another problem is knowing which color to use for the text items in a custom
delegate when the item is hovered or selected or both. The delegate could
assume that the style will draw the background using the highlight color when
the item is selected, but that might not be the case, possibly resulting in
unreadable text. Windows Vista for example doesn't use the normal highlight
color for selected items in icon views and tree views. To make matters worse
it does use it in list views.
For this reason I think it would make sense to extend QPalette with a set of
additional color roles for highlighted item view items, and possibly a role for
the sub text item. It would also be helpful if there was a style hint that
indicated which color role should be used for the text in listviews.
I've attached a simple program that demonstrates some of these issues.
Description: Text Data
|<Prev in Thread]
||[Next in Thread>|
- QStyledItemDelegate feedback,
Fredrik HÃglund <=