Originally Posted by
d_stranz
Move your ellipse up and to the left by 50 each:
path.
addEllipse( QRectF( 0,
0,
100,
100 ) );
path.addEllipse( QRectF( 0, 0, 100, 100 ) );
To copy to clipboard, switch view to plain text mode
Hmmm.... why so?
This works perfectly fine:
#include <QtGui>
public:
QRectF boundingRect
() const { return QRectF(-50,
-50,
100,
100);
} p->drawEllipse(boundingRect());
}
protected:
qDebug() << Q_FUNC_INFO;
}
};
int main(int argc, char **argv) {
view.setScene(&sc);
sc.addItem(new Item);
view.show();
return app.exec();
}
#include <QtGui>
class Item : public QGraphicsItem {
public:
Item(QGraphicsItem *parent = 0) : QGraphicsItem(parent) {}
QRectF boundingRect() const { return QRectF(-50, -50, 100, 100); }
QPainterPath shape() const { QPainterPath p; p.addEllipse(boundingRect()); return p; }
void paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) {
p->drawEllipse(boundingRect());
}
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *e) {
qDebug() << Q_FUNC_INFO;
}
};
int main(int argc, char **argv) {
QApplication app(argc, argv);
QGraphicsScene sc;
QGraphicsView view;
view.setScene(&sc);
sc.addItem(new Item);
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks