PDA

View Full Version : EnterEvent and LeaveEvent don't work perfectly



krisztiantobias
31st July 2012, 14:32
Hello, my problem is the next. I want a hover (enterEvent) effect and an animated hide effect (leaveEvent) with EnterEvent and LeaveEvent.
That works fine on the early, but if I do 5-6 really fast call, can not be called anymore anyone Event :(



timer2 = new QTimer(this);
connect(timer2, SIGNAL(timeout()), this, SLOT(slowlyHide()));

void Clock::enterEvent(QEvent *event){
dragButton->show(); //dragbutton is an extended qlabel
update();
}
void Clock::leaveEvent(QEvent *event){
if(!timer2->isActive())
timer2->start(200);
}

void Clock::slowlyHide(){
dragButton->setOpacity(dragButton->getOpacity()/2);
if(dragButton->getOpacity() < 5){
timer2->stop();
dragButton->setOpacity(255);
dragButton->hide();
}
update();
}

It's a bug or what?

Added after 26 minutes:

Gif: http://imageshack.us/photo/my-images/853/current2.gif/

StrikeByte
31st July 2012, 15:19
Did you try to debug it?
add qDebug("enter event") and qDebug("leave event") (outside the if statements) you can see if the event still gets triggered

this has nothing to do with the problem, but maybe you can use a propertyanimation for a smooth fading out and in (for the extra oemf effect) :p.

krisztiantobias
31st July 2012, 17:32
Yeah, I tried.



...
QEnterEvent(0x28d5d0)
QLeaveEvent(0x28d7d4)
QEnterEvent(0x28d5d0)


A QEnterEvent is the last, after the program don't get more event with this code as well:


void Clock::enterEvent(QEvent *event){
qDebug() << event;
}
void Clock::leaveEvent(QEvent *event){
qDebug() << event;
}

If I open the context menu, the QLeaveEvent is coming, but until that nothing...

krisztiantobias
31st July 2012, 20:47
After the 7. enterEvent the leaveEvent doesn't work...
http://img32.imageshack.us/img32/201/bugr.gif

tescrin
31st July 2012, 22:08
Here's what I've thought of:
-Enter and leave events won't work if something grabs the mouse
-What happens when you enter and leave and enter again? The timer doesn't get restarted, it looks like it just keeps doing it's thing.
Maybe something breaks because of this.
-Is it always 7? Try it at different speeds, different numbers of times, etc.. These will reveal the type of problem it is. If it's always 7 it has to do with some limitation in somethings structure (probably), if it's always a certain amount of time, or happens only if you do it quickly (or something) you're timer is probably screwed up some how.
--By this I mean try it really slowly one time then really fast another time; see if you can predict how and when it will fail.


Also, I don't think your code would slowly fade. It looks like the timer times out, and then makes the thing less opaque than it was by a factor of 2. You'd have to leave the clock like 6 times (waiting each time) for it to fade; at least that's what it looks like.

That's all I can think of.

krisztiantobias
31st July 2012, 22:22
-Enter and leave events won't work if something grabs the mouse

You can see, nothing happened.



-What happens when you enter and leave and enter again? The timer doesn't get restarted, it looks like it just keeps doing it's thing.
Maybe something breaks because of this.
No, that gif was without any code. In the events was only qDebug and a counter.



-Is it always 7? Try it at different speeds, different numbers of times, etc.. These will reveal the type of problem it is. If it's always 7 it has to do with some limitation in somethings structure (probably), if it's always a certain amount of time, or happens only if you do it quickly (or something) you're timer is probably screwed up some how.
No, it's absolutely random (1-20)



Also, I don't think your code would slowly fade. It looks like the timer times out, and then makes the thing less opaque than it was by a factor of 2. You'd have to leave the clock like 6 times (waiting each time) for it to fade; at least that's what it looks like.

The timer doesn't work, that was without timer...

The OS is W7 64 bit, maybe that is the problem, I really don't know...

StrikeByte
2nd August 2012, 13:21
Is it possible to upload a compilable version, so i can try it. (running w7 64-bit and ubuntu)

krisztiantobias
5th August 2012, 06:24
I choosed an another way, so it's does not matter...