QGraphicsSvgItem zeichnen

Alles rund um die Programmierung mit Qt
Antworten
anno1988
Beiträge: 280
Registriert: 23. Januar 2009 20:49

QGraphicsSvgItem zeichnen

Beitrag von anno1988 »

Hallo,
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);


Dateianhänge
Bildschirmfoto.png
Bildschirmfoto.png (44.07 KiB) 1219 mal betrachtet
upsala
Beiträge: 3946
Registriert: 5. Februar 2006 20:52
Wohnort: Landshut
Kontaktdaten:

Beitrag von upsala »

Du setzt manuell die Größe um und wunderst dich, daß nur noch Unsinn gezeichnet wird?

Und im paintEvent die skalierung ändern und ein anderes Item selbst zeichnen.

Lies doch bitte mal die Doku zu QGraphicsView & Co. durch und überdenke deinen Code nocheinmal.
Antworten