Results 1 to 5 of 5

Thread: QMainWindow Minimize

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

    Default QMainWindow Minimize

    I'm trying to find documentation regarding a signal or event when I click Minimize on a QMainWindow.
    Basically, when I click Minimize, I want to know about it.
    Any Advice?

    Windows 7 64, Qt 5.

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 96 Times in 93 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindow Minimize

    QWidget::changeEvent() seemingly notifies changes in the window state (event type QEvent::WindowStateChange). See the docs for details.

  3. The following user says thank you to yeye_olive for this useful post:

    Henry Blue Heeler (3rd July 2014)

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,553
    Thanks
    13
    Thanked 1,580 Times in 1,509 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QMainWindow Minimize

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

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

    Henry Blue Heeler (11th July 2014)

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

    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 

  7. #5
    Join Date
    Oct 2009
    Posts
    483
    Thanked 96 Times in 93 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    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, 18:09
  2. Replies: 3
    Last Post: 13th November 2011, 09:12
  3. Replies: 2
    Last Post: 29th June 2011, 16:45
  4. Associate a minimize zone to QMainWindow
    By lixo1 in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2009, 14:48
  5. Why will my QMainWindow not minimize properly?
    By ZB in forum Qt Programming
    Replies: 2
    Last Post: 20th September 2006, 19: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.