Results 1 to 6 of 6

Thread: how costly i sthis??

  1. #1

    Default how costly i sthis??

    hi,

    I have seen that in

    void paint(QPainter *painter,
    const QStyleOptionGraphicsItem *option,
    QWidget* /*widget*/);

    {
    painter->setClipRect(option->exposedRect);//update only the area which is visible currently

    }

    How costly is this?? is it resetting the region needed to be painted or is it clipping the qgraphicsitem itself??.Is it a better way to do this ,i just want to paint the part of item which is visible

  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: how costly i sthis??

    How costly is clipping or drawing only on the clipped area? Clipping is in general expensive so if you don't really need it try to avoid it. The operation you pasted is similar to the "selection tool" you might know from painting application - it restricts all operations to the selected area. You can still perform them on any area you want but they will only have effect on the masked region.

  3. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how costly i sthis??

    Mmmm... clipping by itself is not that expensive. What is expensive however is relying on it (and only it) to make sure no content is drawn out of given bounds. Clipping is a (very) suboptimal way to achieve that goal (because the whole drawing is performed but it is only "committed" in the areas marked as "writeable" by the clipping) and, as wysota mentioned though not very clearly IMO, it is way better to manually ensure that your rendering code does not draw anything out of bounds.
    Current Qt projects : QCodeEdit, RotiDeCode

  4. #4

    Default Re: how costly i sthis??

    Hi,

    Can any one provide any example how i could achive this??

  5. #5
    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: how costly i sthis??

    Quote Originally Posted by fullmetalcoder View Post
    Mmmm... clipping by itself is not that expensive.
    Depends if you clip to a rectangle or to a path/region.

  6. #6
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how costly i sthis??

    Quote Originally Posted by wysota
    Depends if you clip to a rectangle or to a path/region
    Sure but the example provided here clearly uses (or would use) rectangle clipping so this is not an issue.

    Can any one provide any example how i could achive this??
    Depends what you mean by "this"

    By the way, it seems we still haven't clearly answered one of your original question :

    setting a clip rect (or region or path) to a QPainter does not have any effect on the updating mecanism. It only affect the painting. When the paint event is called, the updating mecanism is already at its end (well not quite yet but the remaining path is out of your reach). Clipping at this point only affects the result of the painting operations in a very simple way : all operations requested will be performed but pixels will only be written to the screen if they are within the bounds allowed by the clipping.

    To schedule repainting of a given region of an item you have to pass the coordinates of that region (must be a rectangle) to QGraphicsItem::update(QRectF& r) method.
    Current Qt projects : QCodeEdit, RotiDeCode

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.