Hi,
when i click into the graphicsView with the following example a QGraphicsEllipseItem will be added.
My problem is that the already existing QGraphicsEllipseItems seem to "mov"e each time when a new item is added.
I want the visible are of the scene to be fixed.
When i set the scene rect to a fixed rect, the items stay in position, but then the scene rect is not correct.
I want the sceneRect to include all items and thad the visible area of the scene stays fixed when i add new items.
Can anyone help?
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QApplication>
#include <QGraphicsEllipseItem>
#include <QMouseEvent>
#include <QPointF>
public:
QPointF pos
= mapToScene
(event
->pos
());
}
};
int main(int argc, char **argv) {
MyView v;
v.setScene(&scene);
v.show();
return app.exec();
}
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QApplication>
#include <QGraphicsEllipseItem>
#include <QMouseEvent>
#include <QPointF>
class MyView : public QGraphicsView {
public:
void mousePressEvent(QMouseEvent *event) {
QPointF pos = mapToScene(event->pos());
scene()->addItem(new QGraphicsEllipseItem(pos.x()-5,pos.y()-5,10,10));
}
};
int main(int argc, char **argv) {
QApplication app(argc, argv);
QGraphicsScene scene;
MyView v;
v.setScene(&scene);
v.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks