PDA

View Full Version : QGraphicsItem disappear when zoom is too large.



Zikoel
26th July 2011, 11:25
Hi at all,

I have in my scene a custom QGraphicsItem. When I apply to the scene a certain zoom it suddently disapperas? Why? And how can I prevent if from happening?

Thank you all, and sorry for my bad english!

mcosta
26th July 2011, 18:03
Can you post the code of your Item paint() method?

Zikoel
29th July 2011, 11:41
This is my code.



void CMCanvasPointer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {

Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(QPen(QColor(Qt::red), 2));

float x = center->x();
float y = center->y();

painter->drawLine( QLineF(x, y+2, x, y+length ) );
painter->drawLine( QLineF(x, y-2, x, y-length ) );
painter->drawLine( QLineF(x+2, y, x+length, y ) );
painter->drawLine( QLineF(x-2, y, x-length, y ) );

painter->drawRect(boundingRect());
}


It make a "+" in a scene and moving che point "center" it can translate in the window.

mcosta
29th July 2011, 12:04
What is the value of length??

if length is 2, you're painting 4 points

Zikoel
29th July 2011, 12:16
length is a global variable and the value is 20.

mcosta
29th July 2011, 21:55
From QT Docs



void QGraphicsItem::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ) [pure virtual]
...
Make sure to constrain all painting inside the boundaries of boundingRect() to avoid rendering artifacts (as QGraphicsView does not clip the painter for you).
...


How do you set the boundingRect() ?
Show the code of CMCanvasPointer::boundingRect().

SixDegrees
30th July 2011, 13:14
What zoom level does the object disappear at? You may be over- or under-flowing the painter's underlying units.