QML: Donut pie graph without QtChart module - qt

I have a Qt-QML application where I have a donut pie graph.
Now I am using a ChartView with a PieSeries (full of PieSlice items)
I need to change my QML class to avoid using QtChart module.
Which would be the best idea?

While it is totally unclear what are your objections against QtCharts #Diego, there are plenty of options. Some of options:
Draw whatever you want on Canvas2d -- in this case you need to implement all charts painting.
Use Charts.js -- Simple yet flexible JavaScript charting for designers & developers in your project (integrate via the same Canvas2d). There are few of implementation that brings Charts.js into QML, e.g.:
https://github.com/MichaelVoelkel/ChartJs2QML
https://github.com/qyvlik/Chart.qml

Related

Comparison of two approaches to rendering raw OpenGL into a QML UI in Qt

According to this article, there are two main methods for rendering raw OpenGL into an application whose UI is otherwise managed by QtQuick's scene graph. In short, they are (according to my understanding):
Calling raw OpenGL methods in hand-written code that is hooked into the scene graph's render loop through some APIs exposed by QtQuick.
Rendering the raw OpenGL portion of your scene to a QQuickFramebufferObject, which is treated like a component in the scene graph and itself rendered as if it were a texture.
What are the advantages/disadvantages of the two approaches?
The issue with QQuickWindow::beforeRendering() or QQuickWindow::afterRendering() signals is that all OpenGL drawing done from their slots will be appropriately under or over the rendered Qt Quick scene. If this is good enough for you — ie. you only want to draw a custom OpenGL background or some kind of overlay — then go for it.
If you need more, ie. use OpenGL to render some QtQuick Item that placed within the scene graph, then you have to go with the second option: rendering OpenGL to a framebufferobject that is used as a texture on some QtQuick Item.
As the documentation article you have linked to states, it gives you more possibilities (using multiple rendering contexts or even multiple rendering threads) but also comes with performance cost. It is also more troublesome to implement.
Generally, as the option 1) is usually inadequate, you are forced to go with 2). It is the only way to use raw OpenGL within a QtQuick scene that I know of.

Custom real-time drawing in Qt5 and Qt Quick 2

I have been looking far and wide to find out how, if it’s possible, you can fill a particular area in a QML screen with an OpenGL context and do custom OpenGL only in that context. I’ve seen plenty of demos where the QML components like buttons, etc lay on top or below a screen-wide OpenGL context (as is typically required by games), but I’d like to be able to situate several distinct OpenGL contexts within QML and have the QML file define how large they are, where they are positioned, etc.
Now, since Qt 5 is all OpenGL under the hood, it makes me wonder if using a Canvas element with custom drawing via javascript could result in similar rendering performance as custom OpenGL? This would be a meaningful alternative but it’s not clear to me how the javascript drawing is handled via runtime compared to custom OpenGL drawing.
What is it that you want to draw? QQuickPaintedItem may be the simplest way to go about it. When you're using QOpenGLFramebufferObject as the target, the painter will use OpenGL to paint the texture. It might be easier than writing your own OpenGL code if all you're doing is 2D.

QtQuick 2.0 vs QGraphicsView (QPainter)

I'm writing right now an application in Python (PyQt / PySide), which should visualise and should give the possibility to edit complex dataflow graphs (like nodes in blender). Additional I want these nodes to display opengl 3D objects (small opengl scenes, like buttons on nodes), images, controls etc.
The GUI will be complex also - it will allow to subdivide to panels and allow in each panel to open a context (like in Eclipse or Visual Studio).
I'm learning QtQuick 2.0 right now and I've read Overview of painting in Qt 5. I'm wondering what are the real benefits of using QtQuick over QPainter.
QtQucik 2.0 no longer uses QGraphicsView as its backend (it uses directly the OpenGL context)
In each technology you can use OpenGL. In each you can draw custom looking buttons and widgets (like nodes, their connections etc) (you can draw them even with QPainter and handle mouse by yourself).
Of course the qml is declarative and can optimize the OpenGL calls, but does it really matter? I've been searching very long for any benchamrks between QPainter (QGraphicsView) and QtQuick 2.0 but found nothing interesting.
So the questions are:
Is really QtQuick the technology "of the future"? Should I use it if it is possible? Will I benefit from it in the future? Or it is simple "another" way of doing the same things like with QPainter with QGraphicsView and QWidgets?
Are the possibilities of QtQuick 2.0 really higher than the PySide / PyQt?
Is the QtQuick more suitable to develop this kind of application or should I stick to PySide / PyQT and QPainter?
The OpenGL mostly matters if you want to embed the UI directly with other OpenGL elements, and especially when you want smooth transitions, animations etc. on limited hardware.
1), 2) are hard to answer - it depends. For a desktop application with complex eclipse-like UI doing everything in QtQuick isn't really feasible. I'd stay with widgets there. Reimplementing Eclipse in QtQuick would be a huge task and would end up in a hardly usable UI that doesn't blend in well with the desktop. If you want animated, custom UI, then I'd go QtQuick. There it's the right tool for the job and mimicking it in QWidget/plain QGraphicsView would be pain.
A1. QtQuick is a modern technology to implementing fluidly advanced UI. It uses Scene Graph as backend which is newest technology to utilising Hardware Acceleration in a high performance and very intelligent approach. Scene Graph has best performance between QPainter, QGraphicsView, Scene Graph if target machine is OpenGL ES 2 capable.
It is very productive but you need to be care about some performance tips to keep performance as high as possible.
It is naturally suitable for MVC/MVC-like patterns but choosing/designing an efficient and suitable model to integrating and interaction between Model/Controller/View needs experience).
A2. Your question is wrong! QtQuick is part of Qt not a new thing parallel to whole Qt.
A3. In my experience, in case of a big and complex applications, you need to be careful about choosing a good approach to integrating C++ and QML (in other words controlling UI from C++).
Also you can create custom elements using QPainter or QGraphicView or QOpenGL or QQuickItem and integrate it with QtQuick based UI.
Keep in mind that static build of QtQuick is not possible now! (AFAIK)
Last word, I suggest you strongly to learn and test it in real world. Because it grows rapidly in Qt Framework and it is the future in my opinion.

Qt drawing with Qt designer

I have tried to search on the internet and here as well, without success though. I am using Qt 4.8.2 and design my app in the Designer, then I write code in VS2010. I would like to show a chart on the application window, e.g. like http://www.infocaptor.com/user_help/help_img/dashboard_line_chart_screen.png , based on some data that are created by the app.
In the Widget Box of the Designer, I can't find any widget related to drawing. So I tried creating a QTextEdit and drawing on that using QPainter. However, this does not work. I can draw on the whole appwindow, but not just on the text edit. So the question is: what widget can be added onto the app window in the designer and that is going to allow me to draw on it using QPainter?
I'm eluded as the documentation says specifically that QPainter can draw on any QWidget which a QTextEdit is...
Any help is much appreciated,
Daniel
The function of "drawing" is tooo complex/unspecific to be included as a specialized widget. You'll have to create it yourself and implement the desired drawing functions.
Here is an example which you can learn from, the scribblearea class could be pretty much what you are looking for. In that case you can copy it to your project and use in in the Qt-Designer by promoting a widget to this class.

Is there a control for displaying code branches in Qt?

I'm trying to display some kind of branches with Qt. How do I go about this? Will I have to draw it myself? Is there some control/thing that will do this for me?
(source: hades.name)
You will have to do it yourself, use QGraphicsScene and QGraphicsView.
To layout the graph, you may want to look at GraphViz - a graph visualisation tool.
You could just use the GraphViz algorithms for layout (using plain output) and then draw using the Qt libraries (QGraphicsScene / QGraphicsView like #cbamber85 recommended), or you could render a PNG from GraphViz and then display it.
You may want to look at KCacheGrind, as this is a Qt application that uses GraphViz for laying out call graphs.

Resources