[solved] minimize event
-
[Solved]
hi i wrote a program i want to hide and sent it to tray when its minimized i used code below
@bool myclass::event(QEvent *event)
{
if (event->type()==QEvent::WindowStateChange && isMinimized())
{
hide();
event->ignore();
}
else{
return QMainWindow::event(event);}
}@
but this happens
before minimize
!http://dl.2rialy.ir/ZiDoM-Ups/91/before.JPG(before)!
after minimize
!http://dl.2rialy.ir/ZiDoM-Ups/91/after.JPG(after)!i dont know why this happens because when i use this code
@
void myclass::closeEvent(QCloseEvent *event)
{
hide();
event->ignore();
}
@
it works fine -
Well, if you minimize a window it is automatically hidden (that's why you minimize it in the first place).
If you are talking about hiding the taskbar entry see "this":http://qt-project.org/forums/viewthread/8902 thread.
-
I tried this
@
int main(int argc, char *argv[])
{
QApplication application(argc, argv);QWidget widget; QMainWindow mainWindow(&widget); mainWindow.show(); return application.exec();
}
@
but it doesn't hide the taskbar icon hides the window to
and when i tried this
@int main(int argc, char *argv[])
{
QApplication application(argc, argv);QMainWindow mainWindow; mainWindow.show(); ShowWindow(mainWindow.winId(), SW_HIDE); SetWindowLong(mainWindow.winId(), GWL_EXSTYLE, GetWindowLong(mainWindow.winId(), GWL_EXSTYLE) | ~WS_EX_APPWINDOW); ShowWindow(mainWindow.winId(), SW_SHOW); return application.exec();
}@
i received some errors -
Snippet #1 does not show a taskbar icon, and so does setting the Qt::Tool window flag - at least for me.
@
void MainWindow::changeEvent(QEvent *event)
{
if (event->type() == QEvent::WindowStateChange)
{
if (isMinimized() == true)
setWindowFlags(windowFlags() | Qt::Tool);
else
setWindowFlags(windowFlags() & ~Qt::Tool);
}return QMainWindow::changeEvent(event);
}@
Using ~WS_EX_APPWINDOW does, as mentioned in the linked thread, not work properly.
-
[quote author="zidom" date="1348914755"]hi i wrote a program i want to hide and sent it to tray when its minimized i used code below
@bool myclass::event(QEvent *event)
{
if (event->type()==QEvent::WindowStateChange && isMinimized())
{
hide();
event->ignore();
}
else{
return QMainWindow::event(event);}
}@
[/quote]hi
@if (event->type()==QEvent::WindowStateChange && isMinimized())
{
hide();
show();
hide();
event->ignore();
}
else{
return QMainWindow::event(event);}@ -
bq.
void MainWindow::changeEvent(QEvent *event) { if (event->type() == QEvent::WindowStateChange) { if (isMinimized() == true) setWindowFlags(windowFlags() | Qt::Tool); else setWindowFlags(windowFlags() & ~Qt::Tool); } return QMainWindow::changeEvent(event); }
I used that it works for hiding but when i want to show the form again
void myclass::trayicon_click(QSystemTrayIcon::ActivationReason reason) { if(reason==QSystemTrayIcon::Trigger) { show(); } }
it looks like this when i show the form !http://dl.2rialy.ir/ZiDoM-Ups/91/after.JPG(show)!
-
This example may help you:
http://doc.qt.digia.com/4.7-snapshot/desktop-systray.html
(void Window::closeEvent(QCloseEvent *event)) -
bq. This example may help you:
http://doc.qt.digia.com/4.7-snapshot/desktop-systray.html
(void Window::closeEvent(QCloseEvent *event))I already saw that but that doesn't help me by the way thank
bq. Use showNormal() instead.
thanks a lot that worked again thanks for following this article and helping me