How to convert QGraphicsItem to SVG element in PySide or PyQt? - qt

I am trying to import SVG as QGraphicsItem in QGraphicsScene and vice versa.
Is there a way to do it with QSvgGenerator, QSvgRenderer or have to build my own method for that.
Also, can't find builtin method for the XML(SVG) representation. Please help.

Related

QML equivalent of QPainterPathStroker

I am trying to create an outline of a path in QML. I read that QPainterPathStroker is able to do this, but it is not in QML. What is the QML equivalent of QPainterPathStroker?
Canvas QML type is the closest one. You can see Canvas examples here.

How to place a QPainter element in QML Rectangle?

There is a diagram which I have drawn with QPainter.
How do I diaplay it in QML's Rectangle?
That diagram will get updated on the runtime.
The question is a bit vague.
Do you have the diagram in a QImage or a QPixmap? Then you can use image providers to expose the diagram to QML, and draw it into a Image element.
Do you have the code that uses a QPainter to draw it, and want to make a QML element that uses such code? In that case, subclass QDeclarativeItem (in Qt Quick 1) or QQuickPaintedItem (Qt Quick 2), override their paint() methods and do the drawing there. You can then register the new type in the QML engine, so you can use a Diagram type in your QML files.

How can I paint on a specific pixel in BlackBerry 10, Qt QML Cpp

I simply want to paint a 1 pixel dot on a specific point on the screen. Is there anyway to do that? In QML or cpp?
Rectangle QML item should works good for you: http://qt-project.org/doc/qt-4.8/qml-rectangle.html
If you need to draw something more specific and more flexible, then you can customize QDeclarativeItem in C++, unset QGraphicsItem::ItemHasNoContents flag in your custom class and implement paint method. More details: http://qt-project.org/doc/qt-4.8/qdeclarativeitem.html

Can't embed OpenGL window into QWidget with XReparentWindow

I'm trying to add better UI for an OpenGL-based program with Qt. Since I can modify that program it's not hard to get the window ID. So I think embedding it into a QWidget would be a good idea. However, it doesn't work like I expected:
After XReparentWindow is called, the OpenGL window lose its decoration, but the position didn't change.
If I use XConfigureWindow to move it to position (0, 0) relative to parent it goes to the top-left corner of the screen, but not the QWidget.
After reparenting, a third window can cover the QWidget, but nothing can cover the OpenGL window.
X11 reported no errors during the whole operation.
It seems the parent of the OpenGL window has been set to the root window instead of my QWidget. What should I do to make it work correctly?
You can replace your current OpenGL window with a QGLWidget which provides an OpenGL context and can be placed into a Qt window directly.
I'm not sure Qt supports XReparentWindow calls like that. The docs don't seem to say it does, so it's probably a bad idea to use it. You could try QWidget::create() instead.

How to draw QGraphicsItem in a MFC view

I'm starting using Qt in my application. My application is MFC based. I want to draw some QGraphicsItems in my currect MFC view, is it possible?
You may say that it could be done by hosting QGraphicsView with QWinWidget in the MFC view, that don't work, however. Because my Canvas (MFC view) supports zooming and rotating while the QGraphicsView itself don't. When I zooming the QGraphicsItem, the QGraphicsView shows scroll bar instead of enlarging itself.
Any suggestion? Thanks!
Theoretically you could use QGraphicsScene::paint to paint the scene with your QGraphicsItems in the buffer, and then draw it to MFC view, but it does not make any sense...
What is the problem with QGraphicsView anyway? Have you taken a look at the rotate(), scale(), translate() or shear() functions of it?
You can turn off the displaying of scroll bard of QGraphicsView by setting the ScrollBarPolcies to Qt::ScrollBarAlwaysOff. (QGraphicsView is a sub-class of QAbstractScrollArea.)
I am not sure I understand what you mean by rotating QGraphicsView itself instead of the content. Without the scroll bars, I don't see the difference. Also much of the functionality of QGraphicsItem like editing as you indicated, depends on event handling in QGraphicsScene and QGraphicsView to work. I don't think plugging just a QGraphicsItem into the MFC view will do what you want.

Resources