PDA

View Full Version : Custom QGraphicsItem



Lis
12th April 2010, 03:31
Hello everyone.
I try to create a custom QGraphicsitem.

This is the code of QGraphicsItemDot.h:

#ifndef QGRAPHICSITEMDOT_H
#define QGRAPHICSITEMDOT_H
#include <QWidget>
#include <QGraphicsItem>
#include <Qpainter>
#include <QRectF>
#include <QLine>
#include <QLineF>
#include <QPoint>
#include <QPointF>
#include <globalTypes.h>

class QGraphicsItemDot : public QGraphicsItem {
public:
//QGraphicsItemDot(QPointF &dot, QGraphicsItem* parent = 0);
void setDot(QPointF argdot);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QPointF dot;
};

#endif

This is the code of QGraphicsItemDot.cpp:

#include "QGraphicsItemDot.h"

//QGraphicsItemDot::QGraphicsItemDot(QPointF &dot, QGraphicsItem* parent) : QGraphicsItem(parent) {
//setDot(dot);
//}

void QGraphicsItemDot::setDot(QPointF argdot) {
prepareGeometryChange();
dot = argdot;
update();
}

QRectF QGraphicsItemDot::boundingRect() const {
return QRectF(2, 2, 2, 2);
}

void QGraphicsItemDot::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
painter->drawPoint(dot);
}

Booth of this files compile ok.
I try to create and return a object like this:

QGraphicsItemDot qDrawData::createItemDot(tpStockDataRow coord) {
//Calculations...
QGraphicsItemDot tmpdot;
tmpdot.setDot(QPointF(xPos, yPos));
return tmpdot;
}

But this throws that error:

Error 1 error C2248: 'QGraphicsItem::QGraphicsItem' : cannot access private member declared in class 'QGraphicsItem' QGraphicsItemDot.h 20

Can someone help me with this problem?
Thank you, Louis.

Lis
12th April 2010, 03:47
I solved it. I have to work with pointers so all QGraphicsItemDot xxx; declarations become QGraphicsItemDot* xxx;