Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QGraphicsView::scale not working



  • Hi,

    I implemented the code below.
    The initial GUI is correct but when I later call to ‘m_pView->scale’ then it is not working, the scale is not changing and nothing happens.
    Any idea what I did wrong?

    class AppMainWnd : public QMainWindow
    {
        QGraphicsScene* m_pScene;
        QGraphicsView* m_pView;
    }
    
    AppMainWnd::AppMainWnd()
    {
        // ...    
        m_pView = new QGraphicsView(this);
        m_pScene = new QGraphicsScene(this);
    
        m_pView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        m_pView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    
        m_pView->setScene(m_pScene);
        ui->verticalLayout->setParent(m_pView); // verticalLayout is of type QVBoxLayout*
        setCentralWidget(m_pView);
    
        QWidget* pMainDisplay = CreateMainDisplay();
    
        m_pView->setViewport(pMainDisplay);
        ui->verticalLayout->setAlignment(Qt::AlignCenter);
        ui->verticalLayout->addWidget(pMainDisplay);
        // ...    
    }
    
    void AppMainWnd::ScaleUI(double dFactor)
    {
        m_pView->scale(dFactor, dFactor); // This does NOT work
    }
    

Log in to reply