I've recently started playing around with the Graphics View Framework.

With this code:

Qt Code:
  1. void ButtonWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  2. {
  3. painter->setPen( Qt::NoPen );
  4. painter->setBrush( QBrush( QColor(255, 0, 0)) );
  5. painter->drawRoundedRect(0, 0, 50, 50, 25, 25);
  6. }
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:

Qt Code:
  1. void ButtonWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  2. {
  3. painter->setPen( Qt::NoPen );
  4. painter->setBrush( QBrush( QColor(255, 0, 0)) );
  5. painter->drawRoundedRect(-20, -20, 50, 50, 25, 25);
  6.  
  7. painter->setBrush( QBrush( QColor(0, 0, 255)) );
  8. painter->drawRoundedRect(-10, -10, 30, 30, 15, 15);
  9. }
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.