相关疑难解决方法(0)

获取QGraphicsView的可见矩形?

我一直在用这个把头发拉出来好几个小时.有一个线程在这里吧,但似乎没有奏效.QGraphicsView :: rect()将返回宽度和高度,但是未正确设置lefttop值(始终为0 - 忽略滚动量).我希望它在场景坐标中,但它应该很容易从任何系统翻译.我不知道什么horizontalScrollBar()->value()和Vert正在回归......似乎是毫无意义的胡言乱语.


@ fabrizioM:

// created here
void EditorWindow::createScene() {
    m_scene = new EditorScene(this);
    m_view = new EditorView(m_scene);
    setCentralWidget(m_view);
    connect(m_scene, SIGNAL(mousePosChanged(QPointF)), this, SLOT(mousePosChanged(QPointF)));
}

/// with this constructor
EditorView::EditorView(QGraphicsScene* scene, QWidget* parent) : QGraphicsView(scene, parent) {
    setRenderHint(QPainter::Antialiasing);
    setCacheMode(QGraphicsView::CacheBackground);
    setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    setDragMode(QGraphicsView::NoDrag);
    scale(1.0, -1.0); // flip coordinate system so that y increases upwards
    fitInView(-5, -5, 10, 10, Qt::KeepAspectRatio);
    setInteractive(true);
    setBackgroundBrush(QBrush(QColor(232,232,232), Qt::DiagCrossPattern));
}
Run Code Online (Sandbox Code Playgroud)

c++ qt qgraphicsview

12
推荐指数
3
解决办法
2万
查看次数

标签 统计

c++ ×1

qgraphicsview ×1

qt ×1