Results 1 to 5 of 5

Thread: QMainWindow Minimize

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: QMainWindow Minimize

    You should receive QWidget::hideEvent() and showEvent() calls on minimise/restore.

  2. The following user says thank you to ChrisW67 for this useful post:

    Henry Blue Heeler (11th July 2014)

  3. #2
    Join Date
    Dec 2013
    Location
    Colorado
    Posts
    45
    Qt products
    Qt5
    Platforms
    Windows Android
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Default Re: QMainWindow Minimize [Solved]

    Thanks Chris, I'll need to try hideEvent() and showEvent().
    changeEvent() worked great for my purposes, e.g.
    Qt Code:
    1. void MainWindow::changeEvent(QEvent *event)
    2. {
    3. event->accept();
    4. if( event->type() == QEvent::WindowStateChange )
    5. {
    6. if( windowState() == Qt::WindowMinimized )
    7. {
    8. doSomething(this);
    9. }
    10. else if( windowState() == Qt::WindowNoState )
    11. {
    12. doSomethingElse(this);
    13. }
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

  4. #3
    Join Date
    Oct 2009
    Posts
    483
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanked 97 Times in 94 Posts

    Default Re: QMainWindow Minimize

    hideEvent() and showEvent() are less specific than QEvent::WindowStateChange; they are called when a widget is hidden/shown for any reason, not limited to a window being minimized/restored/maximized.

    Your code probably overrides more behaviour than you wish. If I were you, I would try this instead:
    Qt Code:
    1. void MainWindow::changeEvent(QEvent *event)
    2. {
    3. QMainWindow::changeEvent(event);
    4. if( event->type() == QEvent::WindowStateChange )
    5. {
    6. if( windowState() == Qt::WindowMinimized )
    7. {
    8. doSomething(this);
    9. }
    10. else if( windowState() == Qt::WindowNoState )
    11. {
    12. doSomethingElse(this);
    13. }
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    That code does interfere with QMainWindow's event handling; it only does something afterwards (which is what you seem to need here).

Similar Threads

  1. Replies: 0
    Last Post: 8th November 2012, 17:09
  2. Replies: 3
    Last Post: 13th November 2011, 08:12
  3. Replies: 2
    Last Post: 29th June 2011, 15:45
  4. Associate a minimize zone to QMainWindow
    By lixo1 in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2009, 13:48
  5. Why will my QMainWindow not minimize properly?
    By ZB in forum Qt Programming
    Replies: 2
    Last Post: 20th September 2006, 18:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.