Cool... I can now initiate a drag on the chess pieces. I've figured out that I can set the position of the QGraphicsPixmapItem by doing setPos(x, y) but I also want to set the width and height. As far as I can tell from reading the doc, I can only do setScale(a number between 0 and 1).
About the incorrect use of the paint event... What about my paint override for the board tiles? Here's what I did there:
if (tileColor == 0) {
} else {
}
painter->drawRect(x, y, width, height);
}
void BoardTile::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
if (tileColor == 0) {
painter->setBrush(QBrush(QColor(251, 201, 159)));
painter->setPen(QPen(QColor(251, 201, 159)));
} else {
painter->setBrush(QBrush(QColor(207, 139, 70)));
painter->setPen(QPen(QColor(207, 139, 70)));
}
painter->drawRect(x, y, width, height);
}
To copy to clipboard, switch view to plain text mode
I was trying to apply this example from the doc for QGraphicsItem to my objects:
{
public:
{
qreal penWidth = 1;
return QRectF(-10 - penWidth
/ 2,
-10 - penWidth
/ 2,
20 + penWidth, 20 + penWidth);
}
{
painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
}
};
class SimpleItem : public QGraphicsItem
{
public:
QRectF boundingRect() const
{
qreal penWidth = 1;
return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,
20 + penWidth, 20 + penWidth);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
}
};
To copy to clipboard, switch view to plain text mode
Why is that a good override for the paint event and why was mine bad?
Bookmarks