[SOLVED] How to remove application's button from taskbar (for minimizing to tray) with Qt 5?
-
I used to have this piece of code for removing from taskbar (with Qt 4, CMainWindow is subclass of QmainWindow):
@void CMainWindow::hideEvent(QHideEvent* pEvent)
{
QWidget::hideEvent(pEvent);
if(isMinimized())
QTimer::singleShot(0, this, SLOT(hide()));
}@It worked, but only on Windows. Now, after transition to Qt 5, it doesn't work at all - hideEvent is only called when application is closed.
How to do it properly? -
I think minimizing a Window does not really "hide" it, so it won't trigger a hideEvent().
Better use changeEvent(QEvent *event) and check for an event of type QEvent::WindowStateChange.
bq. QEvent::WindowStateChange - The window's state (minimized, maximized or full-screen) has changed.
-
This can help:
@
bool CMainWindow::event(QEvent* e) {
bool result = QWidget::event(e);
if(isMinimized())
QTimer::singleShot(0, this, SLOT(hide()));
return result;
}
@ -
Thanks! Has to be like this:
@bool CMainWindow::event(QEvent* e)
{
bool result = QWidget::event(e);
if(e->type() == QEvent::WindowStateChange && isMinimized())
QTimer::singleShot(0, this, SLOT(hide()));
return result;
}@Then it works as intended.