[Qt-jambi-interest] help~~, sth about QPainter

Gunnar Sletta gunnar at trolltech.com
Thu Jul 24 13:23:47 CEST 2008


?? wrote:
> public class GroupEntryDelegate extends QItemDelegate {
>  
>  protected void drawDisplay(QPainter painter, QStyleOptionViewItem 
> option, QRect rect, String text) {
>   rect.setHeight(16);
>   super.drawDisplay(painter, option, rect, text);
>   rect.moveTop(rect.top() + 16);
>   option.setFont(new QFont("Helvetica [Cronyx]", 12));
>   painter.setBrush(QColor.gray);
>   super.drawDisplay(painter, option, rect, "test");
>   System.out.println(rect.size().width() + " " + rect.size().height());
>   System.out.println("drawing");
>  }
> }
>  
> I extend the QItemDelegate to feature myself's QTreeItem. But why the 
> painter doesn't work? The "test" should be in blue and brush style, but 
> it isn't. I want to solve it, how can I correct it?

Hi,

The text color is specified via the pen, so you should be using 
painter.setPen(QColor.gray) rather than setBrush(). In addition to that, 
most style code specify their own colors based on platform spesifics, 
style spesifics or based on the palette in the style option. If you want 
to simply draw a text you might as well just do:

painter.setPen(QColor.blue);
painter.drawText(rect, option.displayAlignment().value(), "test");

or change the palette option which from which the function picks its 
colors...

best regards,
Gunnar



More information about the Qt-jambi-interest mailing list