Re: QGraphicsPathItem Doubt
Reimplement the contains function by deriving a class from QGraphicsPathItem like this
Code:
{
public:
{}
bool contains
( const QPointF & point
) const {
return boundingRect().contains(point);
}
};
Re: QGraphicsPathItem Doubt
One more doubt.
I have the QGraphicsPathItem and its bounding rectangle. I want to change the Pen that draws the bounding rectangle when the item is selected. I dont have the paint function. I just use the default implementation as of now.
How to set the pen for drawing the bounding rectangle when the item is selected. Is there a way to use the default implementation and still achieve this?
Thanks
Arjun
Re: QGraphicsPathItem Doubt
Oh you mean the bounding rect is part of the painterpath ? If thats the case you can't achieve what you wanted. You can draw the bounding rect separately. Then you can control its pen like this
Code:
{
if(o
->State
& QStyle::State_Selected) p->setPen(selectedPen);
else
p->setPen(unselectedPen);
p->drawRect(boundingRect());
}
Re: QGraphicsPathItem Doubt
Quote:
Oh you mean the bounding rect is part of the painterpath ?
No. The bouding rectangle is not part of the painterpath. Its just the QRectF returned by the boudingRect fucntion.
The default paint implemnetation draws it with black pen and dotted lines. I want to chnage this behaviour. So, can I just draw the bounding rect with the new pen over the old one? or can I do it differently?
Thanks a lot
Arjun
Re: QGraphicsPathItem Doubt
In this case , the solution above involving paint event is what you need :)
Re: QGraphicsPathItem Doubt
BTW i had a look at the source code of QPainterPathItem and actually that draws the bounding rect. So the above solution will be drawing the bounding rect twice :)
You can use this hack instead
Code:
{
QStyle::State back
= o
->state;
o
->state
&= ~
QStyle::State_Selected;
//Removes selection flag o->state = back;
if(o
->state
& QStyle::State_Selected) p->setPen(selectedPen);
else
p->setPen(unselectedPen);
p->drawRect(boundingRect());
}
Re: QGraphicsPathItem Doubt
This is what I wanted. About how to avoid painting the bouding rect twice. Thanks man.
Arjun