PDA

View Full Version : QMainWindow Minimize



Henry Blue Heeler
3rd July 2014, 06:34
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.

yeye_olive
3rd July 2014, 09:30
QWidget::changeEvent() seemingly notifies changes in the window state (event type QEvent::WindowStateChange). See the docs for details.

ChrisW67
3rd July 2014, 20:37
You should receive QWidget::hideEvent() and showEvent() calls on minimise/restore.

Henry Blue Heeler
11th July 2014, 04:51
Thanks Chris, I'll need to try hideEvent() and showEvent().
changeEvent() worked great for my purposes, e.g.


void MainWindow::changeEvent(QEvent *event)
{
event->accept();
if( event->type() == QEvent::WindowStateChange )
{
if( windowState() == Qt::WindowMinimized )
{
doSomething(this);
}
else if( windowState() == Qt::WindowNoState )
{
doSomethingElse(this);
}
}
}

yeye_olive
11th July 2014, 09:28
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:

void MainWindow::changeEvent(QEvent *event)
{
QMainWindow::changeEvent(event);
if( event->type() == QEvent::WindowStateChange )
{
if( windowState() == Qt::WindowMinimized )
{
doSomething(this);
}
else if( windowState() == Qt::WindowNoState )
{
doSomethingElse(this);
}
}
}
That code does interfere with QMainWindow's event handling; it only does something afterwards (which is what you seem to need here).