Hey guys,
first of all english isn't my first language.
I got some problems to creat my own QGraphicsItem. First of all i will show u what i got already:
postit.h
#ifndef POSTIT_H
#define POSTIT_H
#include <QGraphicsItem>
#include <QPainter>
#include <QRectF>
#include <QTextItem>
#include <QGraphicsTextItem>
{
public:
protected:
};
#endif // POSTIT_H
#ifndef POSTIT_H
#define POSTIT_H
#include <QGraphicsItem>
#include <QPainter>
#include <QRectF>
#include <QTextItem>
#include <QGraphicsTextItem>
class PostIt : public QGraphicsItem
{
public:
PostIt(QGraphicsItem* parent = NULL);
protected:
void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget);
QRectF boundingRect() const;
};
#endif // POSTIT_H
To copy to clipboard, switch view to plain text mode
postit.cpp:
#include "../header/postit.h"
}
QRectF PostIt
::boundingRect() const{ }
painter->setPen(Qt::black);
painter->setBrush(Qt::yellow);
painter->drawRoundedRect(0,0,400,400,5,5);
painter->drawRoundedRect(0,0,200,100,5,2);
}
}
#include "../header/postit.h"
PostIt::PostIt(QGraphicsItem* parent) : QGraphicsItem(parent){
setFlag(QGraphicsItem::ItemIsMovable);
}
QRectF PostIt::boundingRect() const{
return QRectF(0,0,400,400);
}
void PostIt::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
painter->setPen(Qt::black);
painter->setBrush(Qt::yellow);
painter->drawRoundedRect(0,0,400,400,5,5);
painter->drawRoundedRect(0,0,200,100,5,2);
}
}
To copy to clipboard, switch view to plain text mode
This one looks exactly like i want. But i need to draw text, which is editable. I tried so much with QGraphicsTextItems and searched in the internet. I found some things, but i dont understand how i can draw this GraphicstextItem in my rect.
I addition, i want to display a picture in the rect. It would be perfect if the user can just drag and drop the picture in my rect. Maybe u can give me some tipps for this problem too.
thanks for reading!
Bookmarks