PDA

View Full Version : Mainwindow winks



sophister
9th May 2009, 09:49
Hi to all:
I use the following codes to hide my mainwindow when the mouse leave it, and show it when the mouse enter it. but when the mouse enter the mainwindow, it wrinks all the time.

//mouse leave
void EasyGo::leaveEvent(QEvent *)
{
//如果主界面靠近屏幕上边缘,则进入上边缘以上
QPoint leftTop = pos();
if(leftTop.y() < 6)
{
move(leftTop.x(), -frameGeometry().height() + 6);
return;
}
}

//mouse enter
void EasyGo::enterEvent(QEvent *)
{
QPoint leftTop = pos();
if(leftTop.y() < 0)
{
move(leftTop.x(), 0);
update();
return;
}
}

any idea appreciated.

aamer4yu
9th May 2009, 10:35
Wouldnt it be better if you hide/show you widget on mouse events in the parent window ?
I mean once you hide you window on mouse leave, how do you expect to get enter event ?

I guess it will be better if you trap some area in parent widget and show/hide your window accordingly.

sophister
9th May 2009, 11:21
yeah, but, this is my top level window, so it has no parent window.
Thanks

been_1990
9th May 2009, 18:52
You could set opacity to zero... but I don't know if that uses more cpu/ram....?

sophister
10th May 2009, 11:38
yeah, it does use more cpu and arm.
thanks!!

been_1990
11th May 2009, 01:35
So.. whats your solution?

aamer4yu
11th May 2009, 05:23
I guess changing opacity on enter and leave event would be better as it happens in Winamp.
If you try to hide the window, how do you expect to bring it back ? You will need to monitor the mouse events on the desktop and then bring back your application, which I think would be heavy task for a simple application.

sophister
11th May 2009, 09:39
I have to setMaxmunSize and minimunsize of the window when the mouse enters or leaves the window, i.e, I when the mouse leaves the window, set the window to a smaller one, and set it back to the original size when the mouse enters again.
But, it's not what I want to use……

sophister
11th May 2009, 09:42
I have to setMaxmunSize and minimunsize of the window when the mouse enters or leaves the window, i.e, I when the mouse leaves the window, set the window to a smaller one, and set it back to the original size when the mouse enters again.
But, it's not what I want to use……