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>
public:
//QGraphicsItemDot(QPointF &dot, QGraphicsItem* parent = 0);
};
#endif
#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
To copy to clipboard, switch view to plain text mode
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 { }
painter->drawPoint(dot);
}
#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);
}
To copy to clipboard, switch view to plain text mode
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;
}
QGraphicsItemDot qDrawData::createItemDot(tpStockDataRow coord) {
//Calculations...
QGraphicsItemDot tmpdot;
tmpdot.setDot(QPointF(xPos, yPos));
return tmpdot;
}
To copy to clipboard, switch view to plain text mode
But this throws that error:
Error 1 error C2248: 'QGraphicsItem::QGraphicsItem' : cannot access private member declared in class 'QGraphicsItem' QGraphicsItemDot.h 20
Error 1 error C2248: 'QGraphicsItem::QGraphicsItem' : cannot access private member declared in class 'QGraphicsItem' QGraphicsItemDot.h 20
To copy to clipboard, switch view to plain text mode
Can someone help me with this problem?
Thank you, Louis.
Bookmarks