22 QPointF ptPosition(-10 - nPenWidth, -10 - nPenWidth);
23 QSizeF size(20 + nPenWidth * 2, 20 + nPenWidth * 2);
24 return QRectF(ptPosition, size);
27 virtual void paint(QPainter* ppainter,
28 const QStyleOptionGraphicsItem*,
33 ppainter->setPen(QPen(Qt::blue, nPenWidth));
34 ppainter->drawEllipse(-10, -10, 20, 20);
41 QApplication::setOverrideCursor(Qt::PointingHandCursor);
42 QGraphicsItem::mousePressEvent(pe);
47 QApplication::restoreOverrideCursor();
48 QGraphicsItem::mouseReleaseEvent(pe);
53 int main(
int argc,
char** argv)
55 QApplication app(argc, argv);
57 QGraphicsScene scene(QRectF(-100, -100, 640, 480));
60 QPushButton* pcmdZoomIn =
new QPushButton(
"&Zoom In");
61 QPushButton* pcmdZoomOut =
new QPushButton(
"Z&oom Out");
62 QPushButton* pcmdRotateLeft =
new QPushButton(
"&Rotate Left");
63 QPushButton* pcmdRotateRight =
new QPushButton(
"Ro&tate Right");
65 pView->setRenderHint(QPainter::Antialiasing,
true);
68 scene.addItem(pSimpleItem);
69 pSimpleItem->setPos(0, 0);
70 pSimpleItem->setFlags(QGraphicsItem::ItemIsMovable);
72 QGraphicsPixmapItem* pPixmapItem =
73 scene.addPixmap(QPixmap(
":/haus2.jpg"));
74 pPixmapItem->setParentItem(pSimpleItem);
75 pPixmapItem->setFlags(QGraphicsItem::ItemIsMovable);
77 QObject::connect(pcmdZoomIn, SIGNAL(clicked()),
78 pView, SLOT(slotZoomIn())
80 QObject::connect(pcmdZoomOut, SIGNAL(clicked()),
81 pView, SLOT(slotZoomOut())
83 QObject::connect(pcmdRotateLeft, SIGNAL(clicked()),
84 pView, SLOT(slotRotateLeft())
86 QObject::connect(pcmdRotateRight, SIGNAL(clicked()),
87 pView, SLOT(slotRotateRight())
91 QVBoxLayout* pvbxLayout =
new QVBoxLayout;
92 pvbxLayout->addWidget(pView);
93 pvbxLayout->addWidget(pcmdZoomIn);
94 pvbxLayout->addWidget(pcmdZoomOut);
95 pvbxLayout->addWidget(pcmdRotateLeft);
96 pvbxLayout->addWidget(pcmdRotateRight);
97 wgt.setLayout(pvbxLayout);
virtual QRectF boundingRect() const
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *pe)
int main(int argc, char **argv)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *pe)
virtual void paint(QPainter *ppainter, const QStyleOptionGraphicsItem *, QWidget *)