Use QOpenGLWigdet in QGraphicsView, display will be displayed after hiding, update will not refresh



  • The following is the constructor code that inherits the QGraphicsView class, using QOpenGLWidget:

    M_scene = new QGraphicsScene( this );
    setScene( m_scene );
    setViewport(new QOpenGLWidget(this));

    Call setHidden(true) in other Widgets, and then set to false, call update will not refresh

    It is normal to not use opengl.

    //setViewport(new QOpenGLWidget(this));

    This problem will also appear on the PC and Android platforms, please help confirm what is the reason. Thank you!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What version of Qt are you using ?
    What exact OS version are you running your application from ?
    Can you provide a minimal compilable example that shows that behaviour ?



  • Qt 5.12.2 (i386-little_endian-ilp32 shared (dynamic) release build; by MSVC 2017) on "windows"

    OS: Windows 7 SP 1 (6.1) [winnt version 6.1.7601]

    I am using an open source project, qflightinstruments-20180421, just modified to opengl way, I provide the entire project directly.

    [0_1558000009369_src.zip](Uploading 100%)

    In line 102 of qfi_PFD.cpp, setViewport uses openGLWidget, the following is part of the code

    qfi_PFD::qfi_PFD( QWidget * parent ) :
        QGraphicsView ( parent ),
    ......
    {
        Reset();

    M_scene = new QGraphicsScene( this );
        setScene( m_scene );

    //use openGLwidget
        setViewport(new QOpenGLWidget(this));

    M_scene->clear();

    ......

    Init();
    }

    In the 213 line of MainWindow.cpp, the update display, hidden and displayed in 222 lines per second, the following is part of the code

    Void MainWindow::timerEvent( QTimerEvent *event )
    {
        /////////////////////////////////////
        QMainWindow::timerEvent( event );
        /////////////////////////////////////

    ......

    M_ui->widgetPFD->update();

    Qint64 time2 = QDateTime::currentMSecsSinceEpoch();
        If( time2 - m_time1 > 1000 )
        {
            qDebug()<<m_time1<<time2<<m_steps;
            M_time1 = time2;
            M_steps = 0;
            M_ui->widgetPFD->setTestHidden();

    }

    The following are hidden and show functions
        Inline void setTestHidden()
        {
            setHidden(!isHidden());
        }


  • Lifetime Qt Champion

    @David-Tang You can't upload files here.
    Upload it to some file sharing service and put the link here.


Log in to reply