I'm trying to draw my own objects(inherited from QGraphicsItem) on my own scene (inherited from QGraphicsScene) on mouse click. When I handle mousePressEvent it puts new object in the wrong place (namely it doubles its coordinates while setting and speed while moving).
I handle MousePressEvent like this:
{
if (mouseEvent->button() != Qt::LeftButton)
return;
PPoint
*p
= new PPoint
(QColor(127,
0,
0), mouseEvent
->scenePos
().
x(), mouseEvent
->scenePos
().
y());
addItem(p);
}
void PolygonScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
if (mouseEvent->button() != Qt::LeftButton)
return;
PPoint *p = new PPoint(QColor(127, 0, 0), mouseEvent->scenePos().x(), mouseEvent->scenePos().y());
addItem(p);
QGraphicsScene::mousePressEvent(mouseEvent);
}
To copy to clipboard, switch view to plain text mode
And I create GraphicsScene and GraphicsView this way:
graphScene = new PolygonScene();
graphScene->clear();
graphScene->addPixmap(pix);
ui.
graphicsView->setGeometry
(QRect(5,
5, pix.
width(), pix.
height()));
ui.
graphicsView->setViewportUpdateMode
(QGraphicsView::SmartViewportUpdate);
ui.graphicsView->setScene(graphScene);
ui.graphicsView->show();
graphScene = new PolygonScene();
QPixmap pix = QPixmap::fromImage(image);
graphScene->clear();
graphScene->addPixmap(pix);
ui.graphicsView->setGeometry(QRect(5, 5, pix.width(), pix.height()));
ui.graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
ui.graphicsView->setScene(graphScene);
ui.graphicsView->show();
To copy to clipboard, switch view to plain text mode
Where should i look for the source of troube?
Thank you
Bookmarks