Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Flickering when change QWidget window state between showMaximized() and showFullScreen()
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 5.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    ddonate
    wrote on 22 Oct 2013, 08:41 last edited by
    #1

    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

    1 Reply Last reply
    0
    • N Offline
      N Offline
      NicuPopescu
      wrote on 22 Oct 2013, 11:43 last edited by
      #2

      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!

      1 Reply Last reply
      0
      • D Offline
        D Offline
        ddonate
        wrote on 22 Oct 2013, 15:09 last edited by
        #3

        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)

        1 Reply Last reply
        0
        • N Offline
          N Offline
          NicuPopescu
          wrote on 22 Oct 2013, 15:54 last edited by
          #4

          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 :)

          1 Reply Last reply
          0
          • D Offline
            D Offline
            ddonate
            wrote on 22 Oct 2013, 16:39 last edited by
            #5

            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.

            1 Reply Last reply
            0

            2/5

            22 Oct 2013, 11:43

            • Login

            • Login or register to search.
            2 out of 5
            • First post
              2/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved