Results 1 to 20 of 23

Thread: Multithreading in QGraphicsItem painting

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Multithreading in QGraphicsItem painting

    And to add to that -- painting everything to a pixmap that is created and destroyed in the paint routine and then painting that pixmap to the target device is slower then just painting to that device directly. Using clipping yields an additional performance hit as every paint operation has to check against the clipping rect/region.
    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.


  2. The following user says thank you to wysota for this useful post:

    karankumar1609 (23rd July 2013)

  3. #2
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Exclamation Re: Multithreading in QGraphicsItem painting

    Thanks for all the precious comments., I have converted my paint from painting in pixmap to native painting.
    The difference is sharpness.
    when i use QPixmap it looks pretty sharp but still the time to paint on the screen is same for both native painting or pixmap painting.

    well i have to do that mannually coz size of data and points will be changed at the run time according to slider position.
    I have to do something smarter.,

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Multithreading in QGraphicsItem painting

    Quote Originally Posted by karankumar1609 View Post
    well i have to do that mannually coz size of data and points will be changed at the run time according to slider position.
    When the number of point changes, just create or destroy items representing those points.
    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.


  5. #4
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Multithreading in QGraphicsItem painting

    What if my points are in the range of 1000 - 6000 and my QGraphicsItem bounding rect is 300x200, how does it scale itself accordingly.
    i cant scale my whole QGraphicsView to do that., just because if i scale my view i have to scale everything in the QGraphicsScene.

    And ya i have use QGraphicsGridLayout to set plotter item.
    There is something which i messed, just because i have jumped to my start point from where to start calculation like we have 100000 points and we have to start calculation from 500 to 550 now my pointer jumps to 500 directly and do calculation till 550 .
    But doing this not return me a good result.

    i am trying to find out the way to optimize my calculation to make it sharper.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Multithreading in QGraphicsItem painting

    Quote Originally Posted by karankumar1609 View Post
    What if my points are in the range of 1000 - 6000 and my QGraphicsItem bounding rect is 300x200, how does it scale itself accordingly.
    Bounding rect of your item should be the size of the item (thus the size of the point) and should not be related to item position.

    Here is a code sample that handles 100k items in the scene quite efficiently (use the mouse wheel to zoom).

    Qt Code:
    1. #include <QApplication>
    2. #include <QGraphicsView>
    3. #include <QGraphicsScene>
    4. #include <QGraphicsEllipseItem>
    5. #include <QWheelEvent>
    6. #include <QStyleOptionGraphicsItem>
    7.  
    8. class PointItem : public QGraphicsEllipseItem {
    9. public:
    10. PointItem(QGraphicsItem *parent = 0) : QGraphicsEllipseItem(parent) {
    11. setPointSize(2);
    12. setBrush(Qt::red);
    13. setPen(Qt::NoPen);
    14. setFlag(QGraphicsItem::ItemIgnoresTransformations);
    15. setCacheMode(QGraphicsItem::DeviceCoordinateCache);
    16. }
    17. void setPointSize(qreal s) {
    18. setRect(-s, -s, 2*s, 2*s);
    19. }
    20. };
    21.  
    22. class GraphicsView : public QGraphicsView {
    23. public:
    24. GraphicsView(QWidget *parent = 0) : QGraphicsView(parent) {}
    25. protected:
    26. void wheelEvent(QWheelEvent *event) {
    27. if(event->delta() > 0) {
    28. scale(1.25, 1.25);
    29. } else {
    30. scale( 0.8, 0.8);
    31. }
    32. }
    33. };
    34.  
    35. int main(int argc, char *argv[])
    36. {
    37. QApplication a(argc, argv);
    38. GraphicsView view;
    39. QGraphicsScene scene(0, 0, 10000, 5000);
    40. for(int i=0;i<100000;++i) {
    41. PointItem *item = new PointItem;
    42. item->setPos(qrand() % 10000, qrand() % 5000);
    43. scene.addItem(item);
    44. }
    45. view.setScene(&scene);
    46. view.setRenderHint(QPainter::Antialiasing);
    47. view.show();
    48. return a.exec();
    49. }
    To copy to clipboard, switch view to plain text mode 
    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.


  7. The following user says thank you to wysota for this useful post:

    karankumar1609 (23rd July 2013)

  8. #6
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Thumbs up Re: Multithreading in QGraphicsItem painting

    Hello wysota,

    your example is the pretty simple one.
    But i am working it in a different way.

    What your example does:
    1. Create a View and Scene of a size
    2. plot points(Items) on the scene
    3. Scale the scene accordingly on whele event

    but something i am working on is different
    1. Create a view and scene of a size
    2. create axis and plot area and set them in the layout (Layout for multiple graph stacked in a scene)
    3. read all the data points and initialize to the plot item
    4. On every update plot item draw each graph in it

    The different is i can't use scale for zoomIn and ZoomOut purpose coz i have an item of fixed size., only the drawing will vary
    means item will virtually zoom in and zoom out horizontally via drawing not via scale., coz if i scale my scene each graph and axis will scale instead of the graph item
    and also i have to do something custom with the graph so i did my own painting.

    well when i complete zoomOut your code nt remain smooth., anyway thanks for your code.
    I think there is some issue with the pixmap painting or the calculation.
    may be it should need optimization.

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Multithreading in QGraphicsItem painting

    Then why are you using QGraphicsView at all?
    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.


  10. #8
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Multithreading in QGraphicsItem painting

    i cant scale my whole QGraphicsView to do that., just because if i scale my view i have to scale everything in the QGraphicsScene.
    sorry for missunderstanding.,
    but i said that i dont want to scale my view.
    the problem with the scale is that i have to scale my whole scene .

  11. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Multithreading in QGraphicsItem painting

    Please answer my question.
    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.


  12. #10
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Multithreading in QGraphicsItem painting

    well graphicsView is the best API i have seen for drawing purpose.
    It automatically update its child items which i dont want to handle.
    QWidget need to update manually on each small changes.. that will effect the performance.

    On Widget i have to mannually handle and draw each element.
    like if i have to add a dynamic line element on graph i have to draw it and handle each and every moment.
    In QGraphicsScene its easy.

  13. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Multithreading in QGraphicsItem painting

    Quote Originally Posted by karankumar1609 View Post
    well graphicsView is the best API i have seen for drawing purpose.
    It automatically update its child items which i dont want to handle.
    You only have one item currently.

    QWidget need to update manually on each small changes.. that will effect the performance.
    Based on what you have now, changing location of one point in the plot requires all 100k points to be redrawn. That sounds to me like "each small changes requires manual update of the whole plot".

    On Widget i have to mannually handle and draw each element.
    That's what you do now too. Both QWidget and QGraphicsView use QPainter API for painting. Each time a piece of your data changes, you redraw the whole canvas which is exactly the situation with widgets. With graphics view, modifying one point should only redraw that one point (and possibly others that intersect with it).

    like if i have to add a dynamic line element on graph i have to draw it and handle each and every moment.
    That's what you do now.

    In QGraphicsScene its easy.
    Yes, I know. Unfortunately you're using QGraphicsView like it were a plain widget.
    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.


  14. #12
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Multithreading in QGraphicsItem painting

    ya i did the same with QGraphicsItem like with QWidget.

    Firstly i started my project with different idea, which suits with QGraphicsView.

    nyway thanks for your help. i will do it in QWidget later.
    well is QWidget is faster than QGraphicsView ?

Similar Threads

  1. Painting the inside of a shape in QGraphicsItem
    By xtraction in forum Qt Programming
    Replies: 9
    Last Post: 16th February 2012, 16:06
  2. Painting problem for QGraphicsItem
    By vivekpurohit in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2011, 09:55
  3. specific painting for just one QGraphicsItem
    By jano_alex_es in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2011, 01:12
  4. QGraphicsItem - painting problem for zoomin
    By nileshsince1980 in forum Qt Programming
    Replies: 0
    Last Post: 26th March 2010, 09:02
  5. Force the painting of a QGraphicsItem
    By fabietto in forum Qt Programming
    Replies: 3
    Last Post: 2nd July 2007, 21:28

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.