PDA

View Full Version : Paint QGraphicsItem problem



dreamer
23rd June 2008, 17:30
I'd like to perform a custom painting of my qgraphicsrectitem.
I don't understand the why the Rect is painted, using this code:



void paint (QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget){
QPen p=painter->pen();
painter->setPen(Qt::NoPen);
QGraphicsRectItem::paint(painter,option,widget);

/*My Custom Painting*/

}

mcosta
23rd June 2008, 18:09
The QGraphicsRectItem has it's pen attribute and use it to draw it's shape.

you can do this


void MyRectItem::paint (QPainter * painter,
const QStyleOptionGraphicsItem * option,
QWidget * widget)
{
QPen p=this->pen();
this->setPen(QPen(Qt::NoPen));
QGraphicsRectItem::paint(painter,option,widget);

this->setPen(p);

/*My Custom Painting*/
}

dreamer
23rd June 2008, 19:03
ok, thanks!

aamer4yu
23rd June 2008, 19:18
You are using - painter->setPen(Qt::NoPen);
How come u are getting a rect drawn ?? Or u mean the rect shape is filled ??

Theres a difference between pen and brush. Brush is used to fill the shape, while pen is used to draw lines/shape.