Results 1 to 13 of 13

Thread: Slow painting in QGraphicsView

  1. #1
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Slow painting in QGraphicsView

    Hello all,

    in the program when I am painting some specific objects to the QGraphicsScene it goes very slowly....this only happens when I am painting text.

    I paint the text using a QPainterPath and then adding the text to the QPainterPath.

    I think in this specific example the painting of everything is so slow because the QPainterPath's which print the text overlap.

    So, my question is....does anyone know that if the QPainterPaths overlap, is there any know effects which cause everything to slow down?

    Thanks,

    Jonathan

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Slow painting in QGraphicsView

    Drawing a painter path in general is a complex operation. Perhaps you could draw the painter path once on a pixmap and then draw the pixmap on the screen?
    J-P Nurmi

  3. #3
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Slow painting in QGraphicsView

    how would this work...the pixmap would get painted over the scene? The names are in objects that need to be selectable and need to receive mouseevents, I'm assuming that if the name is a pixmap that if you clicked on the rectangle (bounds) of the name the object wouldn't receive a command....unfortunately this won't fly

    Is there any way to make the drawPath more efficient?

  4. #4
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Slow painting in QGraphicsView

    Are you experiencing this slow down only while moving the objects or do you experience even when it just gets painted (hide/show, maximize view) ?
    If it is due to the former reason and if you are using Qt-4.3 ,then you can perhaps try
    Qt Code:
    1. view->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
    To copy to clipboard, switch view to plain text mode 
    This updates the union of intersecting rects rather than only the regions which improves the speed when there are lots of intersections.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  5. #5
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Slow painting in QGraphicsView

    Gopala Krishna: I just updated from 4.2.3 to 4.3 in the hopes that this would solve the problem....no dice...but the program works fast than with 4.2.3 so thanks for indirectly getting me to upgrade....I find the fastest (with everything working) setting is QGraphicsView::MinimalViewportUpdate

    I still think it has to do with text printing over other text. Please let me know if there is something I can do with the QPath boundaries to help improve this...

    Thanks for the reply Gopala Krishna

    Cheers,

    Jonathan

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Slow painting in QGraphicsView

    Quote Originally Posted by JonathanForQT4 View Post
    I still think it has to do with text printing over other text.
    Remember that you're not drawing text but actually an extremely complex set of curves. Why could you not dump the QPainterPath to a QPixmap and use QGraphicsPixmapItem instead of QGraphicsPathItem?
    J-P Nurmi

  7. #7
    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: Slow painting in QGraphicsView

    You might also be interested in changing the Optimization Flags and the Cache Mode...
    Current Qt projects : QCodeEdit, RotiDeCode

  8. #8
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Slow painting in QGraphicsView

    Quote Originally Posted by JonathanForQT4 View Post
    Gopala Krishna: I just updated from 4.2.3 to 4.3 in the hopes that this would solve the problem....no dice...but the program works fast than with 4.2.3 so thanks for indirectly getting me to upgrade....I find the fastest (with everything working) setting is QGraphicsView::MinimalViewportUpdate
    You are welcome

    BTW can you provide a screenshot of your app ?
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  9. #9
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Slow painting in QGraphicsView

    thanks for all the replies guys...

    as of now I'm just using the painter within void paint method within the reimplemented QGraphicsItem to paint the path.....so the path itself isn't an item...which could be why it laggs so much...

    so I'm going to try and pass the scene in and make an item and add it to the scene...I'll let you guys know how it goes :P



    Gopala Krishna: will provide a screen shot of the app tomorrow when I have a chance

    cheers,

    Jonathan

  10. #10
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Slow painting in QGraphicsView

    ok, I tried doing the whole dumping the path to the qpixmap.....I have a feeling I'm doing it wrong.

    QPixmap something;
    QRect tester((int)myPath.boundingRect().topLeft().x(), (int)myPath.boundingRect().topLeft().y(), (int)myPath.boundingRect().width(), (int)myPath.boundingRect().height());
    something.copy(tester);
    QGraphicsPixmapItem *test = new QGraphicsPixmapItem(something);
    m_parentScene->addItem(test);

    I'm sure this is wrong, as I don't see any text being printed anywhere..but if you could enlighten me as to how to "dump" the path into the pixmap, I would be very happy


    Gopala Krishna, attached is a picture of my program. Some stuff has been edited out...
    Attached Images Attached Images

  11. The following user says thank you to JonathanForQT4 for this useful post:

    Gopala Krishna (15th July 2007)

  12. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Slow painting in QGraphicsView

    Quote Originally Posted by JonathanForQT4 View Post
    if you could enlighten me as to how to "dump" the path into the pixmap, I would be very happy

    Example:
    Qt Code:
    1. QPixmap something(myPath.boundingRect().size().toSize());
    2. QPainter painter(&something);
    3. painter.translate(-myPath.boundingRect().topLeft());
    4. painter.drawPath(myPath);
    5. painter.end();
    6. m_parentScene->addItem(test);
    To copy to clipboard, switch view to plain text mode 
    Hope this clears it out
    J-P Nurmi

  13. The following user says thank you to jpn for this useful post:

    JonathanForQT4 (16th July 2007)

  14. #12
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Slow painting in QGraphicsView

    Just a remark; a classic performance hit when drawing text using QPainterPath is to set the painter pen, or rely on the painter's default pen, forcing QPainter to render the text outline. The outline is extremely complex for text, and in most cases you don't want it - instead you just want to fill the text; i.e., set the brush and disable the pen. So:

    Qt Code:
    1. path.addText("Ladada");
    2.  
    3. QPainter painter(...);
    4. painter.drawPath(path); // <- slow! draws the outline with the default pen set
    5.  
    6. painter.setPen(Qt::NoPen);
    7. painter.setBrush(Qt::black);
    8. painter.drawPath(path); // <- fast!
    To copy to clipboard, switch view to plain text mode 
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  15. The following 2 users say thank you to Bitto for this useful post:

    Gopala Krishna (15th July 2007), JonathanForQT4 (16th July 2007)

  16. #13
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Slow painting in QGraphicsView

    ok, so I've tried jpn and bitto's methods, jpn's doesn't really give me a performance increase, but bitto's does It's faster, but still noticably slower than all other examples...only when you first zoom in -- so only that text is visible in the viewport, does it really speed up to "normal" speed...(like all other examples). I still think this has to do with caching etc....is there a way to further optimize this? I can't seem to believe that this is as good as it gets :-|

    There a way to only display the mypath if it's going to be displayed large than X rect in the viewport or something? I can't think of anything else, since I've already tried the view->setViewportUpdateMode(All different modes :P);

Similar Threads

  1. Speed, transparency, and drop issues with QGraphicsView
    By jefferai in forum Qt Programming
    Replies: 16
    Last Post: 30th June 2007, 16:14

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.