QtQuick: Drawing a Line - Mixing QQuickItem with Canvas or QQuickPaintedItem - qt

I created a QQuickItem which can display a lineplot. This has been done using QSGNodes and should thus be hardware accelerated via OpenGL (as I need to plot many points). Now I want to add an axes to this this plot, and for this I need to draw some lines for the Axis, Ticks (and maybe include a svg for the Arrow head on the axis) and have some text labels.
Does it hurt performance, if I implement this axis as a QQuickPaintedItem or using the Canvas? I am not worried about the performance of drawing the axis, but would my lineplot QQuickItem still be using OpenGL if there is a QQuickPaintedItem at the same place?

Note that SVG files are rasterized and drawn as raster bitmaps, they are not drawn using geometry, so having a SVG won't really save you much aside from the space the image takes on disk, as far as the GPU rendering is concerned, it is just a bitmap. If you want to draw it using geometry, go for QQuickItem and QSGNodes combo again.
QQuickPaintedItem or Canvas- both work in the same way, only the drawing for Canvas is done from JS, so it will be a tad slower. However, it may be a non issue as you typically don't have to redraw chart axis that much.
Of course, each element will be rendered with its respective backend, no need for concern there.

Related

QT coordinate transformation stratetgy

I would like to write a 2D QT application. The goal is to be able to draw rectangles and resize them and drag them around with the mouse. QT offers functionality to do that. The QGraphicsXxx classes natively operate with pixels, but I would like to be able to specify the items' dimensions and positions in length dimensions like meters.
I am looking for a good strategy for constructing an abstraction layer that allows object dimension representation in meters independent of pixels. I was thinking about extending QRectangle with with zoom information, for example, and methods to convert between real-world and screen, i.e. pixel, representation.
That should certainly be possible, but also smells like a road to coordinate-mapping hell. And like a lot of work for a problem that I wouldn't be surprised if it had already been solved more globally/elegantly and that I'm just not finding or understanding from the QT documentation.
Use a QGraphicsScene to layout your objects, all sizes and positions are float and unit independent. Pixel come into play when displaying your Scene using a QGraphicsView. The zooming should be handled by the View so there is no need to do any coordinate transformation in your Scene. You just alter the transformation of your view to show whatever you want.
You can read more about it in the GraphicsView Framework documentation: http://doc.qt.io/qt-4.8/graphicsview.html

how to render a map defined by a matrix of cells using QT Gui?

I have to render using QT a map defined by a matrix of cells in overview mode (think GPS map). I'd like to be able to zoom on it and each cell is defined by its color and some properties (bitmaps to put on the cell). I also need, like in a GPS, to be able to move around (using the directional arrows) in the map.
Right now, I'm thinking about drawing a matrix of QImages on my screen, and loading each one of them with the info of the cells I need, but it doesn't seem like a very good solution.
Thank you for every possibility you might provide.
Your initial idea is a reasonable one, but put all the QImages and info you need into a custom QGraphicsItem and add them to a QGraphicsScene (and fix their position) - then you only need a QGraphicsView to visualise everything. This way you get the BSP painting and selection optimisations, view transformations, and nice animations (if required!) for free.

How to save the pixels in area of the QGRaphicsItem?

Here is the thing, I have develop a manual Annotation Tool for annotating images, you know, use rectangles to mark parts of a human, head, torso, limbs, and store the information like width, height, center point, rotation. I use QT to develop this tiny tool, it's cool, but I face a problem. I want to save the pixels of the image which in a QGraphicsScene in the area of the rectangles (QGraphicsItems), so, I want to know how can I control the pixels of this area?
Thank you very much.
You can render the rectangle area into a QPainter which can be a QImage:
http://qt-project.org/doc/qt-4.8/qgraphicsscene.html#render

Qt drawImage is grainy when painter rotated

I have a transparent PNG file that draws fine when you use a simple drawImage.
When I try to draw it rotated using the painter.rotate(...) method, it draws a very grainy image.
Specifying painter.setRenderHint(QPainter::Antialiasing) does not help.
Is there a way to improve quality? By itself the image is fine.
You should try the QPainter::SmoothPixmapTransform render hint:
Indicates that the engine should use a smooth pixmap transformation algorithm (such as bilinear) rather than nearest neighbor.

Drawing shapes in Flex / Actionscript

I want to develop an image editing application in Flex 4. My initial requirement is to draw various shapes like Line, Rectablge, Triangle, Circle, Star etc in appication. I want to facilitate user to draw shapes using rubber banding like professional applications do.
All shapes would be vector and should look smooth in an size. So, can't use bitmap and scale them.
What are better methods to achieve this?
if you don't want to start from scratch with the basic shapes, there is this framework called degrafa: http://www.degrafa.org/
they have plenty of parametric shapes & curves and advanced features to organize them together.
Make shape editor with some control points. Control points are draggable sprites (circles or squares as you like). When control point is moved, editor must be updated - it may be resize or move action. On resize, draw your vector shape according to new size. The easiest way to make sprite draggable is startDrag() function - you can also set limits there (to stay in editor area or to disable negative sizes).
I have done such editors based on Sprites, added into Flex application with rawChildren.addChild, but you can try to use Canvases instead of Sprites if you wish.

Resources