Results 1 to 2 of 2

Thread: QGraphicsEffect for nested groups

  1. #1
    Join Date
    Aug 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsEffect for nested groups

    I'm using QGraphicsScene and I need to draw item groups having effects. I've found a bug in the application and could reproduce it in a small test application.
    There are 2 conditions that I cannot avoid:
    A) drawing also occurs in a background thread with QGraphicsScene::render (hence no QPixmap's should be used);
    B) in order to draw the effect I need to use a (3rd party) complex implementation that works on QImage.
    The only solution seemed to be simply using QGraphicsEffect::drawSource with QPainter drawing on a QImage then drawing that QImage with the original QPainter (passed to QGraphicsEffect::draw):
    Qt Code:
    1. void BorderEffect::drawImpl(QPainter *p, DrawMethod meth) {
    2. ...
    3. // ===================================================================
    4. // The main question is how can I get the same result
    5. // as with previous 2 methods (Call_QtDrawSource, Draw_QtSourcePixmap)
    6. // when using a temporary QImage buffer for drawSource?
    7. // Is it possible to solve it with setting transformations to pxpainter and p?
    8. const QRectF br = boundingRectFor(sourceBoundingRect());
    9.  
    10. QImage px(br.width(), br.height(), QImage::Format_ARGB32_Premultiplied);
    11. px.fill(Qt::transparent);
    12. {
    13. QPainter pxpainter(&px);
    14. pxpainter.setTransform(QTransform::fromTranslate(-br.left(), -br.top()));
    15. drawSource(&pxpainter);
    16. }
    17. px = apply_3rd_party_effect_to(px);
    18. p->drawImage(br.left(), br.top(), px);
    19. ...
    To copy to clipboard, switch view to plain text mode 
    The problem is I cannot achieve the same effect as with QGraphicsEffect::drawSource or when drawing QGraphicsEffect::sourcePixmap. I attached the whole sample code of the test application (graphiceffect_test_01.zip), there are 3 menu items which correspond to drawSource, sourcePixmap and drawing on intermediate QImage. You can see the difference when resizing the window or dragging the green rectangle item (the first 2 methods/menu-items produce correct effect and the third does not).
    Ideally I need to create a QImage which looks like QGraphicsEffect::sourcePixmap, but since this code might be invoked from a background thread (condition A) I need to reimplement QGraphicsEffect::drawSource which uses internal Qt methods that I cannot access.
    To me it looks like a Qt bug, but I would like to hear a confirming opining. I believe that passing QPainter different from that in QGraphicsEffect::draw to QGraphicsEffect::drawSource is legal, since it's not forbidden by the docs, it produces no qWarnings and it's handled by special if in void QGraphicsItemEffectSourcePrivate::draw (see qgraphicsitem.cpp). So my questions are:
    - May it be really considered a Qt bug or am I missing something?
    - Is there a reasonably easy workaround satisfying conditions A and B?
    Thanks.
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsEffect for nested groups

    So to put it plainly. I need a way to draw the same as QGraphicsEffect::sourcePixmap only as a QImage but without using QPixmap class (i.e. QGraphicsEffect::sourcePixmap().toImage() is no solution). If it's possible then how? If it's not possible with drawSource then this should probably be considered a bug, should it not?

Similar Threads

  1. determining collision of item groups
    By ratsrcute in forum Qt Programming
    Replies: 4
    Last Post: 30th November 2017, 20:09
  2. Read empty groups with QSettings
    By phenoboy in forum Qt Programming
    Replies: 4
    Last Post: 17th October 2013, 08:21
  3. Crash using QGraphicsEffect with QGraphicsItemGroup
    By akiross in forum Qt Programming
    Replies: 5
    Last Post: 18th August 2011, 18:02
  4. QGraphicsEffect on a Phonon::VideoPlayer
    By scary_jeff in forum Newbie
    Replies: 3
    Last Post: 20th January 2011, 01:12
  5. What groups, bands do you listen to?
    By ComaWhite in forum General Discussion
    Replies: 3
    Last Post: 1st November 2010, 15:44

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.