Details
-
Bug
-
Resolution: Incomplete
-
P3: Somewhat important
-
4.6.3
-
None
-
GNU/Linux openSuse 11.2
Description
Hi... suppose we have following class where we want to implement setSize() function for QGraphicsSvgItem
#ifndef MYSVGITEM_H #define MYSVGITEM_H #include <QGraphicsSvgItem> class MySvgItem : public QGraphicsSvgItem { public: MySvgItem(QGraphicsItem* parent = 0); MySvgItem(const QString& fileName, QGraphicsItem* parent = 0); //================== // SETTERS & GETTERS void setSize(QSizeF size); /*inl*/ void setSize(qreal width, qreal height); QSizeF size(); //======================================================== // REIMPLEMENTATION OF VIRTUAL METHODS OF QGRAPHICSSVGITEM void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); QRectF boundingRect(); private: QSizeF size_m; }; inline void MySvgItem::setSize(qreal width, qreal height) { setSize(QSizeF(width, height)); } #endif // MYSVGITEM_H
#include "mysvgitem.h" #include <QSvgRenderer> #include <QStyleOptionGraphicsItem> MySvgItem::MySvgItem(QGraphicsItem* parent) : QGraphicsSvgItem(parent), size_m(-1.0, -1.0) { } MySvgItem::MySvgItem(const QString& fileName, QGraphicsItem* parent) : QGraphicsSvgItem(fileName, parent), size_m(-1.0, -1.0) { } void MySvgItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { //QGraphicsSvgItem::paint(painter, option, widget); Q_UNUSED(widget); Q_UNUSED(option); if (!renderer()->isValid()) return; if (elementId().isEmpty()) renderer()->render(painter, boundingRect()); else renderer()->render(painter, elementId(), boundingRect()); } void MySvgItem::setSize(QSizeF size) { if (size_m != size) { prepareGeometryChange(); size_m = size; update(boundingRect()); } } QSizeF MySvgItem::size() { qreal width = size_m.width(); qreal height = size_m.height(); if (size_m.width() < 0) { width = (renderer()->boundsOnElement(elementId()).size().width()); } if (size_m.height() < 0) { height = (renderer()->boundsOnElement(elementId()).size().width()); } return QSizeF(width, height); } QRectF MySvgItem::boundingRect() { return QRectF(QPointF(0.0, 0.0), size()); }
Now, when you setSize() of some MySvgItem object (which is set to render only one element (setElementId(..))) to size bigger than the size which is set to the element in the source svg file, the result is cropped (as seen in the attached image). To prove that it's really problem of the renderer one can set the size of the actual element in the source svg file to big numbers and voila, it suddenly works (unless you set the size of the MySvgItem object too big).
Note: This bug report might have connection with those two bug reports http://bugreports.qt.nokia.com/browse/QTBUG-5151 and http://bugreports.qt.nokia.com/browse/QTBUG-10903 (the former is closed because it's supposedly a feature and in the latter is provided workaround which does not work).