ich will in eine QGraphicsRectItem, die ich vererbt habe, ein QGraphicsSvgItem zeichnen. Allerding smacht mir as hier ein paar Probleme.
z.B. wird der Scale Faktor hier nicht berücksichtigt und beim ziehen des objekts wird das SvgItem auch nicht richtig gerendert.
Hat da jemand eine Idee wo dran das liegen könnte?
Code: Alles auswählen
#include <QGraphicsSvgItem>
#include <QGraphicsRectItem>
#include <QGraphicsScene>
#include <QCursor>
class MyItem : public QObject, public QGraphicsRectItem {
Q_OBJECT
private:
QGraphicsSvgItem *mforeground_item;
public:
MyItem(QString fileName, QGraphicsItem *parent = 0);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget = 0);
};
//--------------------------------------------------------
MyItem::MyItem(QString fileName, QGraphicsItem *parent) :
QGraphicsRectItem(parent) {
mforeground_item = new QGraphicsSvgItem(fileName);
}
//--------------------------------------------------------
void MyItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget) {
QGraphicsRectItem::paint(painter, option, widget);
mforeground_item->setPos(boundingRect().x(), boundingRect().y());
mforeground_item->scale(0.5, 0.5);
mforeground_item->paint(painter, option, widget);
}
Code: Alles auswählen
MyItem *myitem;
myitem = new Document_Image_Item(":/Camera.svg");
myitem->setRect(x, y, 300, 300);
myitem->setFlag(QGraphicsItem::ItemIsSelectable);
myitem->setFlag(QGraphicsItem::ItemIsMovable);
myitem->setBrush(QBrush(QColor::fromRgb(0, 0, 255, 30)));
scene()->addItem(myitem);