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,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    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.


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

    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 ?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Multithreading in QGraphicsItem painting

    If you use Graphics View incorrectly then QWidget is likely a bit faster since you don't have the overhead of setting up the environment which you are not using anyway. If you use Graphics View correctly then it will likely be much faster than QWidget, especially for use-cases such as yours where you have a lot of small items and a subset of them is changing in time.
    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.


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

    karankumar1609 (24th July 2013)

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

    Default Re: Multithreading in QGraphicsItem painting

    Thanks wysota,

    I have got the problem.
    Well the problem is in the two statements in painting.

    Qt Code:
    1. std::vector<Plot_Aggregation_Element> plotAggregationElement = plotDataValue->plotData();
    2.  
    3. // Each vector contains the data of one day
    4. std::vector<Date_Element> dateElement = plotAggregationElement.at(0).ID[0].ID_vector;
    To copy to clipboard, switch view to plain text mode 

    The above code takes 6-8 millisecond and if there is 8 graph then it takes 6x8 = 48ms.
    Now i have to solve this ., and after that it will be faster than before (60 - 48 = 12ms , thats look great).
    Last edited by karankumar1609; 24th July 2013 at 06:43.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Multithreading in QGraphicsItem painting

    Don't copy all the data -- in the code you quoted you are possibly making two copies of a vector (x8, etc.).
    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. #6
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    27
    Thanked 18 Times in 18 Posts

    Default Re: Multithreading in QGraphicsItem painting

    Hello wysota,

    What is the better option to use data without copying it .

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Multithreading in QGraphicsItem painting

    Return a const reference instead of a copy.
    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.


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

    karankumar1609 (24th July 2013)

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

    Default Re: Multithreading in QGraphicsItem painting

    YAY const reference kills my time., now my plotting time is just not 2-3 ms its 0 ms than 6-8 ms..
    Thanks wysota for your usefull post..

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
  •  
Qt is a trademark of The Qt Company.