Results 1 to 11 of 11

Thread: QGraphicsItem::setCacheMode - how does it work?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItem::setCacheMode - how does it work?

    Subclass QGraphicsRectItem, add some debug messages to this class's paint() method, add an instance of it to your scene and enable caching for it. If paint() gets called after changing the rect of the item, then the blame is in your item code. If it doesn't it's somewhere else (e.g. scene code?).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsItem::setCacheMode - how does it work?

    OK, did this, it works, my original class still doesn't. The good news is that when I rubberband over the new QGraphicsRectItem, its paint() method *isn't* being called, which is exactly what I was trying to achieve in my original class and which I had hoped caching would achieve.

    Time to dig into the code and figure out what's going wrong.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItem::setCacheMode - how does it work?

    A shortlist to check (as always with graphics items):
    1. Is my bounding rect defined correctly (e.g. is it independent of the placement of the item)?
    2. Is my shape defined within the bounding rect?
    3. Is my paint() routine painting only within the bounding rect?
    4. Am I calling prepareGeometryChange() each time the bounging rect is going to change?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:

    d_stranz (1st June 2012)

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsItem::setCacheMode - how does it work?

    1. Is my bounding rect defined correctly (e.g. is it independent of the placement of the item)?
    Thank you, thank you. That's where the problem is. My bounding rect was defined in world coordinates, which resulted in a positive width() but negative height(). I have yet to get it right, but at least the item's paint() method is now being called as expected, and caching is doing the right thing when I rubberband.

    I owe you a beer or six.

    Edit: YES! That was it. Tell me where to send the beer.
    Last edited by d_stranz; 1st June 2012 at 01:33.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItem::setCacheMode - how does it work?

    Quote Originally Posted by d_stranz View Post
    Edit: YES! That was it. Tell me where to send the beer.
    Qt Developer Days 2012. Hopefully...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 25th March 2012, 20:01
  2. Subclassing QGraphicsItem to work as a layer
    By kefir in forum Qt Programming
    Replies: 7
    Last Post: 10th March 2011, 09:42
  3. Replies: 7
    Last Post: 29th November 2010, 19:20
  4. Why QGLFramebufferObject in QGraphicsItem don’t work?
    By Student3000 in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2010, 20:12
  5. QGraphicsItem::setToolTip does not work
    By Nadia in forum Qt Programming
    Replies: 2
    Last Post: 6th September 2009, 19:54

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.