我有一个标准的Graphicviewclass
#ifndef INPUTGRAPHICVIEW_H
#define INPUTGRAPHICVIEW_H
#include <QGraphicsView>
#include <QPaintEvent>
class InputGraphicView : public QGraphicsView
{
public:
InputGraphicView(QWidget* parent= NULL);
protected:
//Take over the interaction
virtual void wheelEvent(QWheelEvent* event);
virtual void mousePressEvent(QMouseEvent *e);
// void mouseMoveEvent(QMouseEvent* event);
private:
QGraphicsScene* Scene;
QGraphicsEllipseItem* ellipse;
std::vector<QGraphicsPolygonItem*> polygon_graphic;
};
#endif // INPUTGRAPHICVIEW_H
我的问题是我希望在Graphicview中间有一个正常的固定坐标系。这样我的x和y e [-5,5]就不多了。
但我不明白坐标系的概念我有我的场景,其中原点(0,0)位于中间?
我试过
setSceneRect(-5, -5, 5, 5);
但是当我使用我的
时void InputGraphicView::mousePressEvent(QMouseEvent *e)
{
QPointF point;
point=mapToScene(e->pos().x(),e->pos().y());
std::cout << point.x() << ", " << point.y() << std::endl;
}
我得到其他坐标。我的起源在中间,但我得到500以上的价值。你知道我能做什么吗?我如何获得固定边界的固定坐标系?
答案 0 :(得分:0)
如果你想在中心有5(0,0),在边缘有5,你还需要调用QGraphicsView::fitInView
来增加变焦系数。你使用不正确的矩形:第3和第4个参数是宽度和高度。
setSceneRect(-5, -5, 10, 10);
fitInView(-5, -5, 10, 10);