[Qt-interest] Query related selection color in Qt

Andre Somers andre at familiesomers.nl
Wed Jun 23 15:33:58 CEST 2010


On 23-6-2010 15:13, Ramesh wrote:
>
> Ya I do agree with that point,
>
> But logically if we think, the control comes to customized paint 
> method here, painter is a pointer, we are going to modify and passing 
> it to the base class.
>
> Where else painter value gets changed?
>

QStyledItemDelegate is the method to do the painting of a delegate just 
like your own one. I would *expect* that method to manipulate the brush 
and pen for it's drawing. It needs to! Why do you think you can modify 
it for your own delegate, but don't want other delegates to do the same?

Still, probably the painter is not actually changed after the call. 
Chances are (without reading the source) that the implementation uses 
QPainter::save() and QPainter::restore(), so you will get back the 
painter the way you left it. Not that that helps you...

Bottom line is, that you need to use another method. You can:
* do the drawing yourself in the delegate (look in QStyledItemDelegate 
for inspiration on how to do that), or
* use the appropriate QAbstractItemModel data roles to set the colors 
you prefer in your model or a proxy model.

Perhaps it is even possible to manipulate the style option passed to 
achieve what you want, but I am not sure about that.

André

> *From:* qt-interest-bounces at trolltech.com 
> [mailto:qt-interest-bounces at trolltech.com] *On Behalf Of *Andre Somers
> *Sent:* Wednesday, June 23, 2010 6:29 PM
> *To:* qt-interest at trolltech.com
> *Subject:* ***SPAM*** Re: [Qt-interest] Query related selection color 
> in Qt
>
> On 23-6-2010 14:43, Ramesh wrote:
>
> Hi,
>
> I want to highlight the selected item text color in listview, for this 
> I am painting  the text in delegate method.
>
> My problem is, if I set the pen to painter and draw the text manually 
> it works, but if the system draw text it doesn't work
>
> May I know the reason why it happens like this?
>
> Here is the sample code of delegate where my problem is occurring.
>
> In this code, I am setting the pen color to painter and passing it to 
> base class to draw, still painter doest draw with the color which I set.
>
> *const* *bool* sel((option.state & QStyle::/State_Selected/) == 
> QStyle::/State_Selected/);
>
> QBrush baseBrush(sel ? option.palette.highlight() : 
> option.palette.base());
>
> QBrush textBrush(sel ? option.palette.highlightedText() : 
> option.palette.text());
>
> QColor color = textBrush.*color*();
>
> painter->*setPen*(*QColor*(0,102,255));
>
> QStyledItemDelegate::*paint*(painter,option,index);
>
> Probably, because QStyledItemDelegate::paint itself sets the color of 
> the pen before painting, based on the style, the palette and the style 
> sheet, I guess.
>
> André
>

-- 
Nokia Certified Qt Developer.
Interested in Qt related job offers or freelance Qt consulting work.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100623/d98c68ed/attachment.html 


More information about the Qt-interest-old mailing list