Details
-
Bug
-
Resolution: Cannot Reproduce
-
P2: Important
-
None
-
4.7.1
-
None
-
Windows 7
Description
If a QGraphicsScene contains a QGraphicsSvgItem, the SVG item will not be rendered when the QGraphicsScene::render() method is called. Instead, the warning output contains a host of "Painter not active" messages. This only seems to happen on Windows (Ubuntu Linux, at least, has not problem), and only with QGraphicsSvgItem instances (other QGraphicsItem instances seem to work fine.)
main.cpp
#include <QtCore> #include <QtGui> #include <QtSvg> int main(int argc, char **argv) { QApplication app(argc, argv); // Set up a temporary svg file. The behavior is not affected if a normal file // is used instead of a temporary file; this is just for convenience of demo // application. QTemporaryFile temp; temp.open(); temp.write( "<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" " "xmlns=\"http://www.w3.org/2000/svg\" width=\"250\" height=\"250\">" "<rect width=\"100%\" height=\"100%\" fill=\"white\"/>" "<circle cx=\"100\" cy=\"100\" r=\"50\" stroke=\"black\" " "stroke-width=\"2\" fill=\"red\"/>" "</svg>"); temp.flush(); temp.close(); QGraphicsScene scene; // If you create, for example, a QGraphicsEllipseItem, everything works fine // when rendering the scene onto a pixmap. // // QGraphicsEllipseItem *item = new QGraphicsEllipseItem(0.0, 0.0, 100, 100); // But using a QGraphicsSvgItem fails. QGraphicsSvgItem *item = new QGraphicsSvgItem(temp.fileName()); scene.addItem(item); // You can display the scene on a view with no problems: // // QGraphicsView view; // view.setScene(&scene); // view.show(); // But rendering onto a pixmap fails. QPixmap pm(scene.sceneRect().toRect().size()); pm.fill(Qt::white); QPainter painter(&pm); scene.render(&painter); // QPainter errors!! QLabel lbl; lbl.setPixmap(pm); lbl.show(); return app.exec(); }
The warning messages start with "QPainter::begin: Paint device returned engine == 0, type: 2"