Results 1 to 7 of 7

Thread: Painting updates

  1. #1
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Painting updates

    Hi.
    I have a QGraphicsScene with items. I have a different view depending on which 'button item' is pressed on the scene. So the view changes if an icon button is pressed.
    Example : Scene view #1 has buttons and items.
    Buttons:
    The buttons are created from a class of it's own, call it class::button, inherits QGraphicsRectItem. This class re-implements the virtual paint function, and the buttons are painted. In this class the painting of the buttons are done, and mouse events are captured when the buttons are pressed.
    Items:
    The item is a polygon with a radial gradient. This is a class:: polygonitem, inherits QGraphicsPolygonItem. This class re-implements the virtual paint function, and the polygon is painted.
    Problem:
    When I press a button/icon on a scene, the button paint function updates the button (due to the event that causes the button to expand and retract. The button class mouse event calls 'update()' to update the button. When the update function is called, it also causes my polygon item to update. The paint function in the polygon class is also called for an update.

    This functionality will slow down the button presses. I do not need the polygon repainted everytime the button is pressed. I know it's probably related to how I implemented the classes and painting. Ideas? When I call 'update()' only the button item is updated?
    Thank you

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

    Default Re: Painting updates

    If boundingRect()s of the button and the polygon intersect, the polygon will get updated. There is not much you can do about it apart from redefining the boundingRects so that they don't intersect or setting the graphicsview into QGraphicsView::NoViewportUpdate mode and do the update yourself.

  3. #3
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Painting updates

    sorry I didn't give you more detail. No, the button items are no where near the polygon item. There is no way they will ever intersect.

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

    Default Re: Painting updates

    Check the boundingRect() for both items. For instance using QRectF::intersects(). Just remember to map those rects to scene coordinates first. It's the bounding rects that may intersect, not the shapes themselves.

  5. #5
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Painting updates

    thanks for the tips. I have done a little more debugging and noticed that when the button is pressed I have a function that scales the button from a timeline slot, the value is updated calling setTransform(QTransform().translate(x(),y()).scale (1 - value / 3.0, 1 - value / 3.0).translate(-x(),-y()));
    If I take out the scaling transformation the button selection still works, and the painting is only restricted to inside the selected button, the polygon is not updated. So the cause of this painting update is when I use the transform on the object.
    Does this tell you anything?
    Thanks.

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

    Default Re: Painting updates

    What do you set the transformation on?

  7. #7
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Painting updates - Solved!

    ahhhhh yes I solved the problem!
    In the viewing class where I setup the view using QGraphicsView I set setViewportUpdateMode(MinimalViewportUpdate). The previous setting was (FullViewportUpdate). Thanks for your help.
    Last edited by QbelcorT; 29th September 2008 at 03:05.

Similar Threads

  1. Qt 4.4.0-rc1 painting performance
    By thomaspu in forum Qt Programming
    Replies: 0
    Last Post: 9th April 2008, 19:13
  2. Slow painting in QGraphicsView
    By JonathanForQT4 in forum Qt Programming
    Replies: 12
    Last Post: 16th July 2007, 10:54
  3. painting a widget outside a paintEvent
    By jayw710 in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2007, 00:18
  4. Painting in QCanvasView
    By JimBrown in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2007, 23:29
  5. About painting
    By Pang in forum Qt Programming
    Replies: 3
    Last Post: 28th March 2007, 18:21

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.