【问题标题】:How to set (0,0) to the top left corner of QGraphicsScene如何将(0,0)设置为QGraphicsScene的左上角
【发布时间】:2021-11-07 07:35:13
【问题描述】:

是否可以将 (0,0) 设置为QGraphicsScene 的左上角?默认情况下,它似乎位于视图的中心:

class GraphicsScene : public QGraphicsScene
{
protected:
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
    {
        // here you can see that (0,0) is at the center of the view
        qDebug() << "movement " << event->scenePos();
    }
};

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    GraphicsScene* scene = new GraphicsScene;
    QGraphicsView* view = new QGraphicsView(scene);

    setCentralWidget(view);
}

【问题讨论】:

    标签: qt qgraphicsview coordinate-systems qgraphicsscene


    【解决方案1】:

    你必须在QGraphicsView中设置alignment

    QGraphicsView* view = new QGraphicsView(scene);
    view->setAlignment(Qt::AlignTop | Qt::AlignLeft);
    

    【讨论】:

      猜你喜欢
      • 2018-08-01
      • 2013-03-03
      • 1970-01-01
      • 1970-01-01
      • 2014-10-26
      • 1970-01-01
      • 2012-04-27
      相关资源
      最近更新 更多