I made all changes you suggested
Set scene size:
graphScene->clear();
graphScene->setSceneRect(0,0,pix.width(), pix.height());
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();
QPixmap pix = QPixmap::fromImage(image);
graphScene->clear();
graphScene->setSceneRect(0,0,pix.width(), pix.height());
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
Constructor, boundingRect and mousePressEvent looks like you posted exactly.
Here is my paint fuction:
{
Q_UNUSED(widget);
painter
->setBrush
(QBrush(color
));
painter->drawEllipse(0, 0, size, size);
painter->setBrush(b);
}
void PPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget)
{
Q_UNUSED(widget);
QBrush b = painter->brush();
painter->setBrush(QBrush(color));
painter->drawEllipse(0, 0, size, size);
painter->setBrush(b);
}
To copy to clipboard, switch view to plain text mode
But now every time i click the mouse on GraphicsView it draws PPoint in the left upper corner. Strange...
This behavior remains even when i write
painter->drawEllipse(x(), y(), size, size);
painter->drawEllipse(x(), y(), size, size);
To copy to clipboard, switch view to plain text mode
as it was before
Bookmarks