Results 1 to 7 of 7

Thread: Custom QGraphicsItem being painted even when completely obscured

  1. #1
    Join Date
    May 2019
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Custom QGraphicsItem being painted even when completely obscured

    Hi all - I have a qt5 app which has a QGraphicsScene into which I place a lot of Elements, a custom class which derives from QGraphicsItem. Element reimplements paint(), boundingRect(), and opaqueArea(). Several Elements should overlap and completely obscure other Elements.

    However, paint() is being called for every Element in the QGraphicsScene (with QStyleOptionGraphicsItem->explosedRect always matching the full boundingRect), even the ones that will be completely obscured by other Elements.

    Is there a way I can avoid painting the Elements which which shouldn't need to be painted due to being obscured?

    Thanks!

  2. #2
    Join Date
    May 2019
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom QGraphicsItem being painted even when completely obscured

    The reason this is important to me is that I have several Elements which are images, but the underlying data is heavily compressed. Decompressing the raw data takes a significant amount of time. So if the rendered element will be fully obscured in the final scene, I don't want to go through the work of decompressing the data.

  3. #3
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom QGraphicsItem being painted even when completely obscured

    Can't you just cache the rendered output and just paint the cached image in the paint event?

  4. #4
    Join Date
    May 2019
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom QGraphicsItem being painted even when completely obscured

    I don't think so... I have hundreds of images being generated on the fly every second. I put them in a QGraphicsScene with a bunch of other QGraphicsItems. The user has the ability to make some of the QGraphicsItems visible/invisible at run time, so at the time the images are generated, I don't know which will be needed and which won't be needed.

    Once an image does get rendered, I cache the rendered image for any repaintings. But the normal use case is to generate new images at 60fps. I do have time to render just the "top layer" of images and keep that frame rate. But because I am also spending time rendering in paint() calls for the lower (obscured) images, I'm overrunning my frame time.

  5. #5
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom QGraphicsItem being painted even when completely obscured

    60fps? and than hundreds of images at this rate? Then you should definitely think about your design. E.g. render the stuff in separate threads. But why such a high frame rate at all?
    Did you take a look at https://doc.qt.io/qt-5/qgraphicsitem...CacheMode-enum ?

  6. #6
    Join Date
    May 2019
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom QGraphicsItem being painted even when completely obscured

    I'd like to avoid the call to paint() in the first place, so caching doesn't help. The high frame rate is because my application takes input from a connected camera which outputs at that rate. I turn its output into processed video.


    Added after 8 minutes:


    Thanks for the suggestions though. I'll think about some other ways I can avoid putting the QGraphicsItems in the scene in the first place
    Last edited by Micah; 5th June 2019 at 23:07.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom QGraphicsItem being painted even when completely obscured

    You should probably consider using a different display technology, e.g. QtQuick, which is rendered hardware accelerated on the GPU.

    Cheers,
    _

Similar Threads

  1. QGraphicsItem are not painted any more
    By dfroze in forum Qt Programming
    Replies: 3
    Last Post: 23rd January 2017, 15:14
  2. Custom QGraphicsItem Resize
    By mvbhavsar in forum Newbie
    Replies: 0
    Last Post: 19th February 2015, 17:29
  3. How can clone custom QGraphicsItem
    By Malloc in forum Qt Programming
    Replies: 0
    Last Post: 7th May 2010, 09:08
  4. Custom QGraphicsItem
    By Lis in forum Qt Programming
    Replies: 1
    Last Post: 12th April 2010, 04:47
  5. Replies: 4
    Last Post: 4th October 2007, 09:03

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.