Results 1 to 3 of 3

Thread: [Solved] Scene-level item-related custom painting

  1. #1
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default [Solved] Scene-level item-related custom painting

    Hello there,
    I'm using the Graphics View Framework.

    I've a scene with many, many items. Most of them luckily aren't visible. I need to draw something like a "force field" around every object. The problem is that such a field shall be globally-calculated, so I've to take the items visible (which shall be pretty fast given BSP), do some calculations, and draw somehow the "force field". It shall be painted behind the items.

    Of course the force field will be bigger than an item, so I will always paint in an area bigger than item's bounding box.

    Now the question is: which is the best (fastest? easiest? more qt-appropriate?) way to draw my "force field"?

    I thought of some options:
    1. paint pixel-by-pixel my force field on a drawable surface (QPixmap? QImage? Which is the more appropriate?) with the size of the viewport and then use drawBackground and invalidate to paint that image. I'm not sure if drawBackground is conceived to be used like this, and the use of invalidate() is kinda suspicious from my point of view.

    2. paint pixel-by-pixel as above, but using an item with low z-value, positioned at 0.0, sized as big as the view is, using painter->drawImage to draw this item.

    3. paint the "force field" relative to each item in that item's paint() method, and resize the item's bounding rect OR just calling update() when necessary. Item-wise painting seems good to me, but changing bounding rect is just wrong and calling update() may require some explicit caching in some cases.

    Note that background "force field" has to be recalculated on items position change or when the view is changed. It can be cached in the other cases.

    Which way is the best to you, and why?
    Thanks in advance!
    ~Aki
    Last edited by akiross; 4th May 2011 at 19:20.

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

    Default Re: Scene-level item-related custom painting

    If each item has its own force field then implement it as a QGraphicsEffect subclass, it has all you need.
    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.


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

    akiross (4th May 2011)

  4. #3
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default Re: Scene-level item-related custom painting

    Wow thanks!! I never noticed it and seems to fit perfectly! yay!

    EDIT:
    I didn't knew about graphics effect at all... This will allow me to easily achieve new interaction features I didn't think of before. Wysota, I'll raise a statue in your honor.


    Added after 1 29 minutes:


    How is it possible to assign a single effect instance to multiple items? I tried, but the ownership seems to change.
    Last edited by akiross; 4th May 2011 at 20:55.

Similar Threads

  1. Replies: 0
    Last Post: 10th March 2011, 11:44
  2. Custom event gets not propagated to the top level widget
    By nightghost in forum Qt Programming
    Replies: 0
    Last Post: 29th January 2009, 09:06
  3. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  4. background painting in the Scene
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 7th January 2008, 19:56
  5. Painting directly on the scene
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 27th September 2007, 13:55

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.