Is there any minimizeEvent in Qt
-
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. -
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. -
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! -
The code doesn't work on Windows. The main window simplly turns white!
-
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.