Results 1 to 11 of 11

Thread: QGraphicsWidget disappear when scrolling QGraphicsView

  1. #1
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsWidget disappear when scrolling QGraphicsView

    I draw few objects and connections between them. All objects are subclassed from QGraphicsWidget.
    If I scroll view so that part of grey rectangle is not visible - then all lines/connections are gone. Lines/Connections are set as children to those rectangles.
    The same situation with lines between rectangles. There's one big QGraphicsWidget set as parent for them and used to expand view - this big widget is a parent for lines/connections between rectangles. And they disappear too.
    For me it looks like some kind clipping.

    That's how I paint rectangles (smaller one have different colour) .
    Qt Code:
    1. QColor cGray(Qt::gray);
    2. cGray = cGray.light();
    3. QBrush brush(cGray);
    4. painter->setBrush(brush);
    5. painter->drawRect(0,0,size().width(),size().height());
    To copy to clipboard, switch view to plain text mode 

    And connections/lines.
    Qt Code:
    1. QPen stPen;
    2. stPen.setWidth(2);
    3. painter->setPen(stPen);
    4. painter->drawLines(m_vPathLines);
    To copy to clipboard, switch view to plain text mode 

    Params set for QGraphicsView
    Qt Code:
    1. m_ptrSceneView = new QGraphicsView;
    2. m_ptrSceneView->setInteractive(true);
    3. m_ptrSceneView->setDragMode(QGraphicsView::ScrollHandDrag);
    4. m_ptrSceneView->setScene(&m_RP3Scene);
    5. m_ptrSceneView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    To copy to clipboard, switch view to plain text mode 





    Could some one tell me - how to set this Graphics Environment, so lines/connections won't disappear when I scroll?

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: QGraphicsWidget disappear when scrolling QGraphicsView

    Try to start you application with a different graphicssystem and see whether it makes any difference. See the documenation of QApplication constructor for a list of possible values for graphicssystem.
    It's nice to be important but it's more important to be nice.

  3. #3
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsWidget disappear when scrolling QGraphicsView

    QApplication::setGraphicsSystem() can be set with 'native', 'raster' and 'opengl'. There's no difference between them - problem hasn't been solved. Only use of 'opengl' is different - it crashes app somewhere deep inside in QGLGlobalShareWidget during start-up event processing.

    Thank you for suggestion, but my problem still exist.

  4. #4
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: QGraphicsWidget disappear when scrolling QGraphicsView

    Does it make any difference when you remove the m_ptrSceneView->setViewportUpdateMode(QGraphicsView::FullViewport Update); ?
    It's nice to be important but it's more important to be nice.

  5. #5
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsWidget disappear when scrolling QGraphicsView

    Difference between update modes is only how much he redraws. FulllViewportUpdate redraws everything - and that why lines disappears after one scroll. With others update modes - it redraws only some small part of screen. And this part is without my lines.

    This is screenshoot with SmartViewportUpdate update mode after three moves down and three up.
    It looks like when I scroll down - it doesn't redraw lower part of lines. It leaves screen as it was, but in places revealed by scroll there's nothing. The same when I move scroll up - it draws empty space where lines should be. When I get to the top - it draws visible part of line, but rest isn't draw.


    The same here - with MinimalViewportUpdate update mode after scroll to the bottom of scene and back.

  6. #6
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: QGraphicsWidget disappear when scrolling QGraphicsView

    Can you create an about 100 lines example application that shows that bug so I can try out here?
    It's nice to be important but it's more important to be nice.

  7. #7
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsWidget disappear when scrolling QGraphicsView

    That's the simplest program. I even didn't have to implement connection objects to show result.
    If you run it, make view smaller - to fit inside only one rectangle - and perform scroll down (with mouse or keys).
    You'll see that part of rectangle which wasn't visible isn't redraw (small circles aren't draw entirely) .

    http://www.nopaste.pl/Source/l5k.txt

    EDIT:
    And in this one I've added connections. Like above - this time ALL small circles (CRectSmall) are drawn, but only 2 or 3 of connections for each rectangle is being draw.

    http://www.nopaste.pl/Source/l5n.txt
    Last edited by T4ng10r; 21st January 2010 at 11:26.

  8. #8
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsWidget disappear when scrolling QGraphicsView

    But why are you using QGraphicsWidget's for such things, like drawing circles? Can't you use QGraphicsItem subclasses with properly implemented boundingRect() (and optionally shape()) and paint() ?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  9. #9
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsWidget disappear when scrolling QGraphicsView

    With reimplementing boundingRect I had lots of problems. Mainly positioning inside parents and on scene. In other situation I needed info about position of others scene object - but they weren't set till final object placement. QGraphicsWidget gave me ability to set size and pos and used them in other places without waiting for final scene placement where position and size are stored.

  10. #10
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsWidget disappear when scrolling QGraphicsView

    Quote Originally Posted by T4ng10r View Post
    With reimplementing boundingRect I had lots of problems.
    You didn't spend enough time on reading docs and analyzing given examples. Bounding rectangle is in item's coordinates so if you have rectangle item 20x20 then bounding rectangle returned by boundingRect() should QRectF(0,0,20,20).
    Then drawing in paint() is also done in item's coordinates so doing like this:
    Qt Code:
    1. painter->drawEllipse(pos().x(), pos().y(), 20, 20);
    To copy to clipboard, switch view to plain text mode 
    will cause painting outside the item's bounding rect, which effects you can see in your app. The proper code would be:
    Qt Code:
    1. painter->drawEllipse(0, 0, 20, 20);
    To copy to clipboard, switch view to plain text mode 
    assuming that bounding rect is at least with w=20, h=20;

    Mainly positioning inside parents and on scene. In other situation I needed info about position of others scene object - but they weren't set till final object placement. QGraphicsWidget gave me ability to set size and pos and used them in other places without waiting for final scene placement where position and size are stored.
    It is rather logical for me that item has no position if it is not added to any scene yet (or any parent) because there is no valid position. And notice that pos() is in parent's coordinates and scenePos() in scene's.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  11. #11
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsWidget disappear when scrolling QGraphicsView

    When I changed base class for Connection from QGraphicsWidget to QGraphicsPathItem - it solved my problem. I didn't even have to change or reimplement boudingRect() - it's done automatically.

Similar Threads

  1. QGraphicsView and Scrolling
    By validator in forum Qt Programming
    Replies: 5
    Last Post: 8th September 2017, 00:27
  2. items in view would disappear on scrolling
    By sepehr in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2009, 07:20
  3. Custom scrolling of QGraphicsView
    By hb in forum Qt Programming
    Replies: 0
    Last Post: 12th August 2008, 10:10
  4. QGraphicsView scrolling problem with 4.3.0
    By hb in forum Qt Programming
    Replies: 8
    Last Post: 30th August 2007, 22:18
  5. Replies: 3
    Last Post: 20th February 2007, 13:02

Tags for this Thread

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.