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
) {
if( event
->type
() == QEvent::WindowStateChange ) {
if( windowState() == Qt::WindowMinimized )
{
doSomething(this);
}
else if( windowState() == Qt::WindowNoState )
{
doSomethingElse(this);
}
}
}
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);
}
}
}
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).
Bookmarks