Results 1 to 7 of 7

Thread: QGraphicsItem disappear when zoom is too large.

  1. #1
    Join Date
    Jul 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGraphicsItem disappear when zoom is too large.

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem disappear when zoom is too large.

    Can you post the code of your Item paint() method?
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Jul 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem disappear when zoom is too large.

    This is my code.

    Qt Code:
    1. void CMCanvasPointer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
    2.  
    3. Q_UNUSED(option);
    4. Q_UNUSED(widget);
    5. painter->setPen(QPen(QColor(Qt::red), 2));
    6.  
    7. float x = center->x();
    8. float y = center->y();
    9.  
    10. painter->drawLine( QLineF(x, y+2, x, y+length ) );
    11. painter->drawLine( QLineF(x, y-2, x, y-length ) );
    12. painter->drawLine( QLineF(x+2, y, x+length, y ) );
    13. painter->drawLine( QLineF(x-2, y, x-length, y ) );
    14.  
    15. painter->drawRect(boundingRect());
    16. }
    To copy to clipboard, switch view to plain text mode 

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

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem disappear when zoom is too large.

    What is the value of length??

    if length is 2, you're painting 4 points
    Last edited by mcosta; 29th July 2011 at 12:05. Reason: updated contents
    A camel can go 14 days without drink,
    I can't!!!

  5. #5
    Join Date
    Jul 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem disappear when zoom is too large.

    length is a global variable and the value is 20.

  6. #6
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem disappear when zoom is too large.

    From QT Docs

    void QGraphicsItem:aint ( 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().
    A camel can go 14 days without drink,
    I can't!!!

  7. #7
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem disappear when zoom is too large.

    What zoom level does the object disappear at? You may be over- or under-flowing the painter's underlying units.

Similar Threads

  1. Replies: 1
    Last Post: 16th November 2009, 06:25
  2. QGraphicsItem point selectable "Problem in Zoom"
    By avis_phoenix in forum Qt Programming
    Replies: 0
    Last Post: 21st July 2009, 18:20
  3. QGLWidget with text - zoom in / zoom out
    By h123 in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2008, 10:56
  4. Sending large datagrams(very large)
    By marcel in forum General Programming
    Replies: 1
    Last Post: 16th February 2008, 22:55
  5. How to efficently fade out large QGraphicsItem.
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2007, 11:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.