Flickering when change QWidget window state between showMaximized() and showFullScreen()



  • Hi,

    I have problems with 'WindowStateChange' events in my QWidget.
    I have created a simple test widget with 3 buttons, to set window state:
    Normal: showNormal();
    MAX: showMaximized();
    FullScreen: showFullScreen();
    and trace window state events (QEvent::WindowStateChange).

    When I change 'normal' < > 'max' there is no problem (altough i receive twice 'max' event), BUT when i change 'max' < > 'fullscreen' i receive this events:

    'max' --> 'fullscreen'

    0 No State
    4 FullScreen

    'fullscreen' --> 'max'

    6 Maximized
    4 FullScreen
    6 Maximized
    2 Maximized

    with code like this:
    @ state = windowState();
    if ( state & Qt::WindowMaximized )
    qDebug() << state << "Maximized";@

    So my widget has in both cases a strange flickering. That is, when 'max' --> 'fullscreen', it has an 'intermediate' "normal" state (0), and when 'fullscreen' --> 'max', it has several 'intermediate' states...

    In my application, I must show/hide things when app is normal/maximized/fullScreened, so this flickering is really a problem.

    Is it possible to do anything?

    Thanks in advance,

    Diego



  • Hi,

    try this

    @void MainWindow::on_pushButtonNormal_clicked()
    {
    showNormal();
    }

    void MainWindow::on_pushButtonMaximize_clicked()
    {
    if(windowState() == Qt::WindowFullScreen)
    setWindowState(Qt::WindowFullScreen | Qt::WindowMaximized);
    else
    setWindowState(Qt::WindowMaximized);
    }

    void MainWindow::on_pushButtonFull_clicked()
    {
    if(windowState() == Qt::WindowMaximized)
    setWindowState(Qt::WindowMaximized | Qt::WindowFullScreen);
    else
    setWindowState(Qt::WindowFullScreen);
    }

    void MainWindow::changeEvent ( QEvent * event )
    {
    if(event->type() == QEvent::WindowStateChange)
    {
    qDebug()<<"sender name="<<sender()->objectName();
    QWindowStateChangeEvent stateEv = static_cast<QWindowStateChangeEvent>(event);

        qDebug()&lt;&lt;"state ="<<windowState();
        qDebug()<<"old state ="<<stateEv->oldState();
    }
    

    }@

    now each transition should have just two events like from normal to maximize as you have described ... don't think you can get rid of the second event, but the overall effect is better: no more flickering

    hope this helps!

    Cheers!



  • Hi,

    Firs, thanks for your quick help!

    I have tried your code and:

    • 'max' to 'full' works great, flickering avoided ;):

    @void MainWindow::on_pushButtonFull_clicked()
    {
    if(windowState() == Qt::WindowMaximized)
    setWindowState(Qt::WindowMaximized | Qt::WindowFullScreen);
    else
    setWindowState(Qt::WindowFullScreen);
    }@

    • 'full' to 'max':

    If current state is 'full', why you add 'full' to new state ('max')?
    @ Qt::WindowFullScreen | Qt::WindowMaximized@

    This change works fine for me with if:

    @on_pushButtonMaximize_clicked()
    {
    setWindowState(Qt::WindowMaximized);
    }@

    • With this test: 'normal' --> 'max' --> 'full' --> 'normal', my widget loses window frame... I trace received states every change:

    PRESSED MAX -----------------------------------
    state = 2 (max)
    old state = 0 (NoState)

    state = 2 (max)
    old state = 0 (NoState)

    PRESSED FS ------------------------------------
    state = 0 (NoState)
    old state = 2 (max)

    state = 6 (max & full)
    old state = 2 (max)

    PRESSED NORMAL --------------------------------
    state = 6 (max & full)
    old state = 4 (full)

    state = 0 (NoState)
    old state = 2 (max)

    state = 0 (NoState)
    old state = 6 (max & full)

    The problem is when state change is 'max & full' --> 'normal' (6 --> 0), since the following cases work (window does NOT lose frame):

    'full' -> 'normal' (traces: 4 --> 0)
    'max' -> 'normal' (traces: 2 --> 0)



  • bq. If current state is ‘full’, why you add ‘full’ to new state (‘max’)?
    Qt::WindowFullScreen | Qt::WindowMaximized
    This change works fine for me with if:
    on_pushButtonMaximize_clicked()
    {
    setWindowState(Qt::WindowMaximized);
    }

    you're right ...

    to keep frame (done invisible in full state) try this in handler for normal state:

    @ if(windowState() == (Qt::WindowMaximized | Qt::WindowFullScreen))
    {
    setWindowState(Qt::WindowMaximized);
    setWindowState(Qt::WindowNoState);

    }
    else
        showNormal();@
    

    you see Qt::WindowMaximized | Qt::WindowFullScreen is our faked state while is full and frame is hidden, and states must go from full->max->normal to make frame visible again

    hope it works, though it's weird :)



  • Ok, with your code frame is not lost, thanks ;)

    Now my application has NOT this great flickering, but I think 'temporal' states can not be avoided, are they? I mean:

    When 'max' --> 'full', I receive 'normal' (0) before max&full (6)

    When 'max&full' --> 'normal', I receive 'max' (2) before 'normal (0). This case is logic, since I set 2 states (2 steps) to keep frame.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.