Subclassing QStyledItemDelegate + Selection colors



  • hi there,

    i have the following problem:
    i subclassed QStyledItemDelegate to the costumize the displaying of items in a QListView.
    everything works except for the coloring.

    so far i use the superclass' paint method to draw the selection (transparent blue box in my in 7 theme).
    The Qt::DataRole in the model i supply returns an empty QVariant, so only the selection box drawn.
    this works:

    @
    void DataViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
    const QModelIndex &index) const
    {

      QStyledItemDelegate::paint(painter,option,index);
      // my stuff...
    

    }
    @

    however i have a problem with keeping the text i draw afterwards contrasting with the selection box.
    i tried using something like this:

    @
    ..
    if( option.state & QStyle::State_Selected )
    {
    painter->setPen( option.palette.highlightedText().color() );
    }
    else
    {
    painter->setPen( option.palette.text().color() );
    }
    ..
    @

    this works for example in the classic theme since selections are dark blue, and the highlighted text color is white.
    it does however not work for the windows 7. theme.
    i also have the feeling that the highlighted text color is aimed at highlighted text in text boxes rather than
    for text of highlighted items.

    can you give me some directions to where i can find the related documentation?

    thnks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.