Results 1 to 13 of 13

Thread: QGraphicsItem is not drawn again?

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default QGraphicsItem is not drawn again?

    Hi all,

    I have the following problem;

    I have a scene and items in it. Once I zoom in the scene, some of the items go off the scene normally. But when I zoom out, I don't the items that are there before I zoomed in.

    What could be the possible problem?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem is not drawn again?

    What happens if you zoom so, that for example an item is only half out site the view area, and then zoom back, will you see the whole object item again, or only the part that was not zoomed "out"?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QGraphicsItem is not drawn again?

    If only a part of an item is seen after zooming in, then no problem after zooming out. If the item is completely off the scene after zooming in, then nothing appears about the item.

    Is it more clear now?

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem is not drawn again?

    can you show your zooming code?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QGraphicsItem is not drawn again?

    I'm afraid I can't.

    But you see the problem is not about zooming. I guess I failed in updating of the relevant items issue or the scene itself.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem is not drawn again?

    But you see the problem is not about zooming. I guess I failed in updating of the relevant items issue or the scene itself.
    Probably, but that should be visible in the zooming code, since then we can see what happens when you zoom out again...

    But without code it very hard to help...
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QGraphicsItem is not drawn again?

    Batu olm bi gavra hele ya felaket sıkıldım. batu olmazsa seyhun o da olmazsa bu işin ordinasyüsü levent.

  8. #8
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QGraphicsItem is not drawn again?

    The problem here is basicly because of item's removal from the scene bounding rect. So how can I put the item back into the scene rectangle when it's gone out of it by zooming in action , if I zoom out in the scene again?

  9. #9
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem is not drawn again?

    Why are you managing yourself the items viewed in your scene?

    Since Qt do the job for you and compute the visible items based on QGraphicsItem::boundingRect, you will get in QGraphicsView::drawItems the list of visible items.
    So no need to remove or add items.

    Are you computing the zoom yourself in the scene, in your custom items or elsewhere?

  10. #10
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QGraphicsItem is not drawn again?

    I guess you misunderstood me. I didn't remove or add items when I zoom in or zoom out. This is what I think as a possible reason that the items are no longer visible once they are off the scene's bounding rectangle. It is also strange that the program still enters item's paint method although it's not drawn.

    I deal zooming stuff in the view by the way.

  11. #11
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem is not drawn again?

    So that means that the item are seen by Qt, according to its bounding rect.

    Can you post a simplified version of your zoom function?

    There is probably a coordinates conversion error of your items position, so they are drawn out of the viewed rect.

    Another questions :
    * Why not using Qt built-in QGraphicsView::scale?
    * Do you manage derived QGraphicsItem with overloaded paint?

  12. #12
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QGraphicsItem is not drawn again?

    Hi,

    sorry but I can't because I'm using different library for such operations(zooming, rotating etc.) and the functions are hidden which means not available. I just called setRange(+/- rangeAmount) and it does. Sorry fot that.

    By the way, don't you think that items would have drawn wrongly at the begining or at the situations in which the items are in still scene's rectangle if there is a coordinate error?

    Anyway regarding your last questions,

    I didn't prefer to use it because I deal with geographic coordinates( latitudes and longitudes) so that's why we use different library as I mentioned.

    And I don't think my paint functions are overloaded. They're just dealing with paint issues.

  13. #13
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Angry Re: QGraphicsItem is not drawn again?

    Quote Originally Posted by zgulser View Post
    By the way, don't you think that items would have drawn wrongly at the begining or at the situations in which the items are in still scene's rectangle if there is a coordinate error?
    That why we can help you if you provided some code. Maybe in your loop there is something obvious you don't see now. Maybe your are cumulating zoom scale factor instead of applying it globally, maybe it is the result of integer division...

    Can't you even sum up the data life cycle : creation and adding to the scene, setting position and geometry? It is hard to help you without knonwing what your are doing.

    If you never scale the view by native Qt method scale, I guess you are overloading the paint method of the view and compute yourself relative position of items and their size in pixel coordinates. But then it is only painting, isn't it?
    In that conditions what is the difference with drawing in a QWidget?

    Quote Originally Posted by zgulser View Post
    I didn't prefer to use it because I deal with geographic coordinates( latitudes and longitudes) so that's why we use different library as I mentioned.
    It is only a matter of coordinate system reference. You only need to choose one for you scene, and convert item coordinates when adding.
    Since 1 unit is 1 pixel at scale 1, you can fix your system projection and unit, then position your items and set their size. Then let Qt do the rendering of visible item for you.
    All you have to do it convert your data when creating items and painting them, according to the projection you are using for your scene : plane projection for latitude/longitude in degrees or seconds, or UTM or another metric projection

    An easy way to use QGraphicsView is to choose a projection system for your scene, geographic or metric.

    So you can derived QGraphicsItem :
    * when you add it on the scene, just set a member data to your item (passing in constructor for instance)
    * set its position in scene coordinate (using your conversion libraries),
    * implement the QGraphicsItem::boundingRect, that return the rect in scene coordinate (you can use your libraries to compute it and even optimize in your object the way to do it only once,
    * overload QGraphicsItem::paint. The paint method gets in its arguments the rect of visible portion of your data ( in scene coordiante so in the projection you have chosen) and the level of detail (the scale factor) set by the QGraphicsView::scale. You can then use in paint event the library you want you draw in the painter, in relative pixel coordinate of the item. If any part of the rect is visible in the scene, a paint is triggered.


    Therefore, picking and moving items, zooming and navigating through the view is managed by Qt and call paint for item that need to be displayed.

    Instead of concentrate on the view, can't you focus on items?

    This may save you a lot of work, don't you think?

Similar Threads

  1. QGraphicsItem doesn't inherit QObject?
    By xyzt in forum Qt Programming
    Replies: 6
    Last Post: 26th September 2011, 14:59
  2. Replies: 2
    Last Post: 25th March 2011, 09:18
  3. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  4. Replies: 1
    Last Post: 25th February 2009, 00:34
  5. QGraphicsScene - order of images drawn
    By bjh in forum Qt Programming
    Replies: 2
    Last Post: 29th November 2007, 15:41

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.