Ich wollte für meine Animation ein QGraphicsObject machen und dann setGeometry und geometry hinzuführen. Kleiner bekomme ich folgende Fehler:
Wäre lieb, wenn ihr mir helfen könntet.moc_lockscreen.cpp:126: error: ‘geometry’ was not declared in this scope
moc_lockscreen.cpp:132: error: ‘setGeometry’ was not declared in this scope
Code: Alles auswählen
#ifndef LOCKRECTITEM_H
#define LOCKRECTITEM_H
#include <QGraphicsObject>
#include <QPainter>
class LockRectItem : public QGraphicsObject
{
Q_OBJECT
Q_PROPERTY(QRectF geometry WRITE setGeometry READ geometry)
public:
LockRectItem(QGraphicsItem *parent = 0);
void setGeometry(const QRectF &rect);
QRectF geometry()const;
private:
QRectF boundingRect() const;
void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget = 0);
int width;
int height;
int posX;
int posY;
};
#endif // LOCKRECTITEM_H
#include "lockrectitem.h"
LockRectItem::LockRectItem(QGraphicsItem *parent)
: QGraphicsObject(parent)
{
width = 0;
height = 0;
}
QRectF LockRectItem::boundingRect() const
{
return QRectF(0,0,width,height);
}
void LockRectItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setBrush(QBrush(QColor(80,80,80)));
painter->setPen(Qt::NoPen);
painter->drawRect(0, 0, width, height);
}