xyzt
22nd March 2008, 17:11
i try to learn QT and I wrote MyItem class inherits the QGraphicsItem class. i have added a line to the paint method to see what is going on while runnig. i saw that it wrotes the string twice.i couldnt understand why...
here is my code:
#ifndef MYITEM_H_
#define MYITEM_H_
#include <QGraphicsItem>
class MyItem:public QGraphicsItem
{
public:
MyItem();
virtual ~MyItem();
QRectF boundingRect() const;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *e);
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
};
#endif /*MYITEM_H_*/
#include "MyItem.h"
#include <QtGui>
MyItem::MyItem():
QGraphicsItem(0,0)
{
}
MyItem::~MyItem()
{
}
void MyItem::mousePressEvent(QGraphicsSceneMouseEvent* e){
QGraphicsItem::mousePressEvent(e);
}
void MyItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget )
{
painter->drawEllipse(100,100,20,20);
qDebug("testing"); // it wrotes the string twice....
}
QRectF MyItem::boundingRect() const
{
}
here is my code:
#ifndef MYITEM_H_
#define MYITEM_H_
#include <QGraphicsItem>
class MyItem:public QGraphicsItem
{
public:
MyItem();
virtual ~MyItem();
QRectF boundingRect() const;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *e);
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
};
#endif /*MYITEM_H_*/
#include "MyItem.h"
#include <QtGui>
MyItem::MyItem():
QGraphicsItem(0,0)
{
}
MyItem::~MyItem()
{
}
void MyItem::mousePressEvent(QGraphicsSceneMouseEvent* e){
QGraphicsItem::mousePressEvent(e);
}
void MyItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget )
{
painter->drawEllipse(100,100,20,20);
qDebug("testing"); // it wrotes the string twice....
}
QRectF MyItem::boundingRect() const
{
}