I have a simple class inherits QGraphicsRectItem class. I want it to write "testing" in the mousePressEvent() but it doesn't...where am i doing wrong?i examined the tutorials but couldn't find my fault...
scene.addItem(new MyItem(0));
view.show();
return a.exec();
QGraphicsScene scene(0,0,200,200);
scene.addItem(new MyItem(0));
QGraphicsView view(&scene);
view.show();
return a.exec();
To copy to clipboard, switch view to plain text mode
#ifndef MYITEM_H_
#define MYITEM_H_
#include <QGraphicsItem>
{
public:
virtual ~MyItem();
protected:
};
#endif /*MYITEM_H_*/
#ifndef MYITEM_H_
#define MYITEM_H_
#include <QGraphicsItem>
class MyItem:public QGraphicsRectItem
{
public:
MyItem(QGraphicsItem* parent=0,QGraphicsScene *s=0);
virtual ~MyItem();
QRectF boundingRect() const;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *e);
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
};
#endif /*MYITEM_H_*/
To copy to clipboard, switch view to plain text mode
#include "MyItem.h"
#include <QtGui>
{
}
MyItem::~MyItem()
{
}
qDebug("testing");
}
{
painter
->fillRect
(10,
10,
50,
50,
QBrush(Qt
::red,Qt
::SolidPattern));
}
QRectF MyItem
::boundingRect() const {
}
#include "MyItem.h"
#include <QtGui>
MyItem::MyItem(QGraphicsItem* p,QGraphicsScene *s):
QGraphicsRectItem(p,s)
{
}
MyItem::~MyItem()
{
}
void MyItem::mousePressEvent(QGraphicsSceneMouseEvent* e){
qDebug("testing");
QGraphicsRectItem::mousePressEvent(e);
}
void MyItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget )
{
painter->fillRect(10,10,50,50,QBrush(Qt::red,Qt::SolidPattern));
}
QRectF MyItem::boundingRect() const
{
}
To copy to clipboard, switch view to plain text mode
Bookmarks