Re: Minimize to system tray
You can use QWindowStateChangeEvent, and look at the current window state. This event must be handled in the event() function of your dialog.
Regards.
Re: Minimize to system tray
Quote:
Originally Posted by
marcel
You can use QWindowStateChangeEvent, and look at the current window state. This event must be handled in the event() function of your dialog.
Regards.
So I could do something like...
Code:
void MyDialog
::event (QEvent * event
) {
// i have no idea what i should write here, maybe like...
Qt::WindowStates flag = qwsc_event->oldState ();
}
Re: Minimize to system tray
Code:
void MyDialog
::event( QEvent *e
) {
if( e
->type
() == QEvent::WindowStateChange ) {
//Now check to see if the window is minimised
if( isMinimised() )
//Do something here (show the icon in the systray )
}
}
Should work
Edit:
don't do a dynamic cast at every event, instead check the event type
Re: Minimize to system tray
Quote:
Originally Posted by
marcel
Code:
void MyDialog
::event( QEvent *e
) {
if( e
->type
() == QEvent::WindowStateChange ) {
//Now check to see if the window is minimised
if( isMinimised() )
//Do something here (show the icon in the systray )
}
}
Should work
Edit:
don't do a dynamic cast at every event, instead check the event type
OK I will try it, but shouldn't I do something like forward the other events? How would I do that... like when an event is not a WindowStateChange how would I forward it for default processing? Should I do something like...
Code:
void MyDialog
::event( QEvent *e
) {
if( e
->type
() == QEvent::WindowStateChange ) {
//Now check to see if the window is minimised
if( isMinimised() )
{
hide ();
e->ignore ();
}
}
else e->accept ();
}
Re: Minimize to system tray
Sure :).
It was just an on-the-fly example.
Of course you have to forward the other events.
Regards
Re: Minimize to system tray
Quote:
Originally Posted by
marcel
Sure :).
It was just an on-the-fly example.
Of course you have to forward the other events.
Regards
Well actually the function returns a bool so I did this:
Code:
bool MyInstantMessenger
::event (QEvent *e
) {
if(e
->type
() == QEvent::WindowStateChange) {
//Now check to see if the window is minimised
if (isMinimized())
{
e->accept ();
hide ();
}
else e->ignore ();
return true;
}
e->ignore ();
return false;
}
But this messes my application, like the widgets are not drawn and the QCloseEvent is not sent anymore. I also tried setting other combinations like ignoring the message instead of accepting it and returning false instead of true but that didn't either.
Would installEventFilter() work too? I'm looking in to it right now...
Re: Minimize to system tray
One should pass the events to the base class implementation. Also, it's recommended to reimplement more specialized QWidget::changeEvent() instead of QWidget::event().
Code:
void MyInstantMessenger
::changeEvent (QEvent *e
) {
if(e
->type
() == QEvent::WindowStateChange) {
//Now check to see if the window is minimised
if (isMinimized())
{
hide ();
}
}
QDialog::changeEvent(e
);
// QDialog, or whatever the base class is }
Re: Minimize to system tray
Yes, passing the ignored events to the base class will solve your problem.
Re: Minimize to system tray
That didn't help either :(
I also tried accepting and/or ignoring events and also didn't work, the window is still not hidden from the taskbar and the client area not painted.
Re: Minimize to system tray
Code:
bool MyInstantMessenger
::event (QEvent *e
) {
if(e
->type
() == QEvent::WindowStateChange) {
//Now check to see if the window is minimised
if (isMinimized())
{
hide ();
}
}
}
]
Is this what you did?
EDIT: This is what you need to do. You have to let QDialog handle the change event. You must not accept nor ignore the event. Just hide your window.
regards
Re: Minimize to system tray
Quote:
Originally Posted by
marcel
Code:
bool MyInstantMessenger
::event (QEvent *e
) {
if(e
->type
() == QEvent::WindowStateChange) {
//Now check to see if the window is minimised
if (isMinimized())
{
e->accept ();
hide ();
return true;
}
}
}
]
Is this what you did?
Maybe... I tried so many different combinations I can't remember anymore.
Anyways I tried it now and it does the same thing... when I push the minimize button the window minimizes to the taskbar and the taskbar "button for the window" disappears and appears again quickly, and then when I maximize it, the window shows on the screen but the client area is not painted. Obviously it has to be something with some of the events not being forwarded for default processing... i just don't know what I'm missing here... :( :(
Re: Minimize to system tray
Could you show me the actual code? The one that you last tried :)
Re: Minimize to system tray
I just closed Notepad++ and deleted the code... basically I've tried reimplementing changeEvent () or event () sometimes accepting or rejecting the events, sometimes returning true or false or QWidget::changeEvent ()/event() and other different combinations.
I lost 4 hours on this stupid thing and still haven't got it working.
Anyways thanks for the assistance and maybe when I'll feel masochist enough I'll retry it :P
We're from the same country BTW :D
LE: tried the edited one too.. same thing :(
Re: Minimize to system tray
Quote:
Originally Posted by
aLiNuSh
That didn't help either :(
I also tried accepting and/or ignoring events and also didn't work, the window is still not hidden from the taskbar and the client area not painted.
I faced the same problem.
Anyone has a solution to these issues?
Thanks in advance.
Re: Minimize to system tray
Hi !
I also have the problem with the systrayicon and minimize
so i try following ...
Code:
// Overload original event-handler:
bool MainWindow
::event(QEvent *evt
) {
// Check if Window-State changed to minimize ...
if(evt
->type
() == QEvent::WindowStateChange) {
//Now check to see if the window is minimised
if (isMinimized())
{
// Call the Hide Slot after 250ms
// to prozess other events ....
qApp->processEvents();
QTimer::singleShot(250,
this,
SLOT(hide
()));
evt->ignore();
}
}
// Call original-handler (in this case QMainWindow ...)
}
... this work's on windows !
Re: Minimize to system tray
Use the below code it might be helpful to you.......
Code:
//System tray icon action context menu
minimizeAction
= new QAction(tr
("Mi&nimize"),
this);
connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
maximizeAction
= new QAction(tr
("Ma&ximize"),
this);
connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
restoreAction
= new QAction(tr
("&Restore"),
this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction
= new QAction(tr
("&Quit"),
this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
//ToolbarAction(itemExit).icon(), ToolbarAction(itemExit).text(), parent);
cmenu.addAction(tr("Show"), this, SLOT(show()));
cmenu.addAction(tr("Hide"), this, SLOT(hide()));
cmenu.addSeparator();
cmenu.addAction(minimizeAction);
cmenu.addAction(maximizeAction);
cmenu.addAction(restoreAction);
cmenu.addAction(quitAction);
A solution - Re: Minimize to system tray
Hi, here is a solution, and I think it works quite well in my application:
In the dialog's slot that connects with the activated() signal of the QSystemTrayIcon object, use the setParent() function as:
Code:
{
setParent(NULL, Qt::Window);
showNormal();
sysTrayIcon->hide();
}
}
And in the dialog's event() function:
Code:
bool FtpDialog
::event(QEvent *e
) {
if (e
->type
() == QEvent::WindowStateChange) { if (isMinimized()) {
setParent(tmp, Qt::SubWindow);
sysTrayIcon->show();
e->ignore();
qDebug()<<"event() called";
} else {
e->accept();
}
}
return QDialog::event(e
);
// return with QDialog's event() call anyway. }
Here, 'tmp' is an empty QWidget serving as a provisional 'parent' of the dialog, so that the dialog can be hidden from task-bar when minimized. In fact, you can just pass NULL as the first argument for the 'parent' widget, but in this case probably the re-stored window would exhibit slightly different with the original window size.