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
    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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.


  3. #3
    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 .

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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.


  5. #5
    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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.


  7. #7
    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 ?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.


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

    karankumar1609 (24th July 2013)

  10. #9
    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

    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.

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.


  12. #11
    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

    Hello wysota,

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

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.


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

    karankumar1609 (24th July 2013)

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.