I've recently started playing around with the Graphics View Framework.
With this code:
{
painter->setPen( Qt::NoPen );
painter->drawRoundedRect(0, 0, 50, 50, 25, 25);
}
void ButtonWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen( Qt::NoPen );
painter->setBrush( QBrush( QColor(255, 0, 0)) );
painter->drawRoundedRect(0, 0, 50, 50, 25, 25);
}
To copy to clipboard, switch view to plain text mode
I am able to position an instance of ButtonWidget, using ButtonWidget::setPos(), anywhere exactly I want it to appear on the view (top-right corner for one).
However, when I start drawing multiple shapes I can no longer position an instance of ButtonWidget properly.
Here is the code:
{
painter->setPen( Qt::NoPen );
painter->drawRoundedRect(-20, -20, 50, 50, 25, 25);
painter->drawRoundedRect(-10, -10, 30, 30, 15, 15);
}
void ButtonWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen( Qt::NoPen );
painter->setBrush( QBrush( QColor(255, 0, 0)) );
painter->drawRoundedRect(-20, -20, 50, 50, 25, 25);
painter->setBrush( QBrush( QColor(0, 0, 255)) );
painter->drawRoundedRect(-10, -10, 30, 30, 15, 15);
}
To copy to clipboard, switch view to plain text mode
With this I get the exact appearance of the widget as I want it to be, but no matter what I do I can't position it properly on the view.
I've been reading the docs, tutorials and a couple of books over and over gain but because 2D drawing is so new to me I can't seem to figure out what I am doing wrong.
Bookmarks