Creating a custom-drawn component



  • I'm experimenting with Qt Quick to create a desktop application that does some audio processing. The audio processing will be implemented in C++, and I'd like to be able to update the drawing of the audio waveform in realtime as the user makes some adjustments.

    The problem I have is that it's not clear what the recommended way is to create a user-drawn component. At first I thought I would create a subclass of QQuickPaintedItem, but the documentation for that class says it should only be used for porting older code. I guess I could use it anyway, but I'd prefer to use the "correct" approach.

    I imagine I could use a QQuickImageProvider, and produce a view of the waveform as an image. Or, I could probably use a Canvas and do the drawing in JavaScript, but I suspect passing the audio data from C++ to JavaScript is going to kill performance. It'll probably be better to just draw it in C++.

    If someone could point me towards an example that shows the recommended way of doing something like this, I would appreciate it. There may already be an example included with Qt 5.2, but I could use a pointer to the "best practice".


  • Moderators

    "Here is a good example that shows the basics":http://developer.nokia.com/community/wiki/CS001627_-_Creating_a_custom_QML_element_with_Qt

    Edit: If you want Qt5, you will have to replace some "old" Qt4 objects with the new ones. But anyway, you have a starting point.


  • Moderators

    another one : "usage of dynamic graph":http://developer.nokia.com/community/wiki/QML_Performance_Meter

    This one seems more close to what you want. I haven't tested it though, but seems worth looking at.

    same remark here : it's based on Qt4's QDeclarativeView


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.