Results 1 to 9 of 9

Thread: Applying treatment after screen rendering on specific items with QGraphicsView

  1. #1
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Applying treatment after screen rendering on specific items with QGraphicsView

    Dear Qt workers,

    I am using custom items to display images, polygons and labels in a QGraphicsView.

    Going further on QGraphicsItem features, I want to apply a treatment on the result of the images rendered on the screen. The treatment applies only on image data and not labels, neither polygons.

    So I wondering myself what is the best way to manage an off screen buffer, apply treatments, then display it :
    1 - manage a group item that will be updated with images displayed, and play with paintEvent. Since paintEvent of children will be called before the group item, I can fill an off screen buffer, then apply the treatments in the paintEvent of the group
    2 - overload the [QTCLASS]QGraphicsScene::drawItemsQTCLASS] to first draw raw data of image items, then apply treatments. Polygons and labels can be painted then without interferring.

    Maybe there is another features of QGraphicsView I didn't see.
    Does anyone had the same needs, and how did you do it?

    Thanks by advance.

  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: Applying treatment after screen rendering on specific items with QGraphicsView

    What kind of treatments are we talking about? If you can afford using unstable code, look into Qt 4.6 and the effect classes for graphics items.
    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:

    scascio (30th September 2009)

  4. #3
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Applying treatment after screen rendering on specific items with QGraphicsView

    The treatment involved is histogram stretching, that apply on pixels rendered.
    So I need to compute the histogram of the screen (but without labels and polygons), then stretch it.

    My problem is that the treatment relies on images displayed and is not independant for each item.

    Anyway, QGraphicsEffect in 4.6 seems awesome! Thanks.

  5. #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: Applying treatment after screen rendering on specific items with QGraphicsView

    The simplest way is to reimplement paint() for all items you want to control and adjusting the colours there. A better way would be to do it once - when each item is created - but it's a bit more work.
    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.


  6. #5
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Applying treatment after screen rendering on specific items with QGraphicsView

    I am sorry but I can't see your thought.

    How can I get the display result of items painted, then modifiy the result of the paint event with some parameters that depends on the set of items painted?

    If I move or zoom, the set of items changes, so the treatement is different.

  7. #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: Applying treatment after screen rendering on specific items with QGraphicsView

    Reimplement QGraphicsView::drawItems() and do your calculations there.
    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.


  8. #7
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Applying treatment after screen rendering on specific items with QGraphicsView

    Thanks for confirming.

  9. #8
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Arrow Re: Applying treatment after screen rendering on specific items with QGraphicsView

    Overloading QGraphicsView::drawItems is exactly where I need to do my specific computation.

    So I can call myself the paint of each items with something like I found in the docs and in some QGraphicsScene implementation from koders site at http://www.koders.com/cpp/fidF0D7D36...eneMatrix#L948 :
    Qt Code:
    1. void QMyGraphicsView:drawItems(QPainter * painter, int numItems, QGraphicsItem * items[], const QStyleOptionGraphicsItem options[]) {
    2.  
    3. for(int i=0;i<numItems;i++) {
    4. painter->save();
    5. painter->setMatrix(items[i]->sceneMatrix(), true);
    6. items[i]->paint(painter, &options[i], this);
    7. painter->restore();
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    But I encountered some disagreements. It seems that the default implementation of drawItems is more complicated than that :
    * The items with flag QGraphicsItem::ItemIgnoresTransformations are not rendered properly with the loop I wrote
    * The items cached with QGraphicsItem::DeviceCoordinateCache are painted for each call of drawItems, while the default drawItems save a lot of paintings.

    Does anyone knows where I can find the real default implementation of QGraphicsScene::drawItems according to item flags?

    I will investigation myself on changing my design to do my computation and set attributes of the item of my scene, then call the default drawItems.

  10. #9
    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: Applying treatment after screen rendering on specific items with QGraphicsView

    Sure it is more complicated. According to me you should only do some calculations of yours there, optionally modify the options and then call the base class implementation from QGraphicsView. The rest has to be done from within the items' paint() routine. Of course be aware that you will probably ruin cached items anyway.
    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.


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.