1 Attachment(s)
own subclass of QGraphicsItem problem
I've started implementing my own subclass of QGraphicsItem:
Code:
#ifndef PAWN_H
#define PAWN_H
#include <QtGui>
{
private:
static const int FIGURE_SIZE = 50;
public:
};
#endif // PAWN_H
Code:
QRectF Pawn
::boundingRect() const {
return QRectF(this
->x
(), this
->y
(), FIGURE_SIZE, FIGURE_SIZE
);
}
{
painter->drawRect(boundingRect());
}
Then I've added two items to QGraphicsScene:
Code:
Pawn* first = new Pawn();
first->setPos(0, 0);
Pawn* second = new Pawn();
second->setPos(0, 50);
mainScene.addItem(first);
mainScene.addItem(second);
It looks as follows:
Attachment 9088
Why there is a gap between these two rectangles? Top left vertex of first rectangle is (0, 0) and it's heigth is 50. Top left vertex of second rectangle is (0, 50). They should have a common edge.
Re: own subclass of QGraphicsItem problem
Code:
QRectF Pawn
::boundingRect() const {
return QRectF(0,
0, FIGURE_SIZE, FIGURE_SIZE
);
}