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. Is there any minimizeEvent in Qt
Forum Updated to NodeBB v4.3 + New Features

Is there any minimizeEvent in Qt

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.4k 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.
  • A Offline
    A Offline
    adnan
    wrote on last edited by
    #1

    I couldn't find any minimizeEvent in Qt similar to other events like closeEvent.
    I wish to hide the main window when minimize is clicked.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      You are looking for the "changeEvent()":http://qt-project.org/doc/qt-4.8/qwidget.html#changeEvent.

      @
      void Widget::changeEvent(QEvent *event)
      {
      if (event()->type == QEvent::WindowStateChange)
      if(windowState().testFlag(Qt::WindowMinimized) == true)
      hide();

      QWidget::changeEvent(event);
      

      }
      @
      Brain to terminal. Exemplary.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        adnan
        wrote on last edited by
        #3

        Thanks a lot! for making my job so easy.

        There is a small error in the code:

        @if (event()->type == QEvent::WindowStateChange)@

        should be

        @if (event->type() == QEvent::WindowStateChange)@

        By the way, what is the purpose of this line:
        @QWidget::changeEvent(event);@
        The code works without this line too!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          adnan
          wrote on last edited by
          #4

          The code doesn't work on Windows. The main window simplly turns white!

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            No, the code does not work properly without

            @
            QWidget::changeEvent(event);
            @

            What happens here is an important aspect of C++ polymorphism: you call the implementation of the method you reimplemented in the baseclass. Methods marked 'virtual' in Qt classes often do perform useful work in their base implementations. If you don't call the base implementation, that work will not be done, leading to all kinds of issues. So, make it a habbit to always call this method if you reimplement a virtual method, unless you're absolutely sure that you want to disable the standard behaviour rather than just add to it.

            1 Reply Last reply
            0

            • Login

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