Results 1 to 11 of 11

Thread: QGraphicsWidget disappear when scrolling QGraphicsView

Hybrid View

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

    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.

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

    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.

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

    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.

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

    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.

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

    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
  •  
Qt is a trademark of The Qt Company.