Results 1 to 11 of 11

Thread: QML Canvas plotting continuous sinus wave

  1. #1
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default QML Canvas plotting continuous sinus wave

    Hi there!

    I have a basic question to canvas in QML. Is it possible to update the graph or do I have to redraw the entire graph each time I want to update it?

    My plan is to generate a sinus wave while the program is running. New values will be created about every 10 ms and shall be added to the graph. When the graph reached the end of the x-axis I would like to start updating from the beginning, overwriting the existing values. Assuming the x-axis is 400 px long, I could create an array with 400 values. After reaching index 399 I could start at 0 again. But how do I get this efficiently on my canvas? Can I update singe points or should I do that entirely differently?

    Thanks for comments and/or suggestions.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QML Canvas plotting continuous sinus wave

    Canvas keeps its state across repaints so unless you explicitly tell it to clear itself, old contents will be retained and you can draw just the changed part.
    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
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QML Canvas plotting continuous sinus wave

    Okay sounds good.
    Is it a good idea to do the sinus wave with canvas and plot it pixel by pixel or is there a better way to do that in QML?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QML Canvas plotting continuous sinus wave

    Well... it depends on your skills. You can use the canvas, you can subclass QQuickPaintedItem and paint using QPainter or you can subclass QQuickItem and implement it using scene graph primitives.
    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
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QML Canvas plotting continuous sinus wave

    My skills? Very little. But looking at the options I think I have to go with canvas because these are all the libraries I am allowed to use:
    • libQt5Core.so.5
    • libQt5Quick.so.5
    • libQt5Qml.so.5
    • libQt5Network.so.5
    • libQt5Gui.so.5

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QML Canvas plotting continuous sinus wave

    The libraries don't matter. All of the approaches I mentioned make use of the same set of libraries. If you have little skills then stay away from approach 3.
    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
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QML Canvas plotting continuous sinus wave

    Thanks for the advise.

  8. #8
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QML Canvas plotting continuous sinus wave

    I think I found exactly what I need to get a nice visualisation: G Force Sensor

    If you take out the shadow effect and the simulation values, it is like ten lines of code to do that. How is this possible? I have been reeding though the code a couple of times know but I just do not understand how this is done. Why are the bars moving from right to left? How are new bars added?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QML Canvas plotting continuous sinus wave

    It's using a recursive shader, as far as I remember. Contents of the previous frame is kept, shifted and redrawn the next frame together with the latest data.
    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. #10
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QML Canvas plotting continuous sinus wave

    Yes, your are right. So it says in the blog post where I found it. But I do not understand the code. Where is this shift done?

    If I understand this right, I can use the two files as they are, put the QUItMeterComponent in my QML file and update the meter.value with each increment?

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QML Canvas plotting continuous sinus wave

    Quote Originally Posted by KeineAhnung View Post
    Where is this shift done?
    In the shader, I guess.

    If I understand this right, I can use the two files as they are, put the QUItMeterComponent in my QML file and update the meter.value with each increment?
    Could be. Or you could continue using Canvas
    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.


Similar Threads

  1. Continuous wave Drawing
    By Girish1483 in forum Qt Programming
    Replies: 15
    Last Post: 10th February 2014, 11:01
  2. Replies: 14
    Last Post: 14th September 2012, 15:52
  3. Generating continuous wave (sine/cos)
    By mind_freak in forum Qwt
    Replies: 1
    Last Post: 21st August 2012, 13:47
  4. create non continuous vertical bar
    By bibhukalyana in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2011, 12:35
  5. Continuous Printing
    By Prabha in forum General Discussion
    Replies: 0
    Last Post: 28th July 2010, 12:01

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.