Qt动态靠边收起速度越来越快
#ifndef HIDE_H
#define HIDE_H
#include "box.h"
#include <QTimer>
QTimer *hideTimer = new QTimer;
QTimer *showTimer = new QTimer;
#endif // HIDE_H
/////////////////////////////////////////////
#include "hide.h"
void Box::enterEvent(QEvent *)
{
rect = this->geometry();
rc.setRect(rect.x(),rect.y(),rect.width(),rect.height());
QObject::connect(showTimer, SIGNAL(timeout()), this, SLOT(showSlot()));
if(rect.bottom() < 40)
showTimer->start(15);
}
void Box::leaveEvent(QEvent *)
{
rect = this->geometry();
rc.setRect(rect.x(),rect.y(),rect.width(),rect.height());
QObject::connect(hideTimer, SIGNAL(timeout()), this, SLOT(hideSlot()));
if(rect.top() < 2 && rect.bottom() > 2)
hideTimer->start(30);
}
void Box::hideSlot()
{
rect = this->geometry();
rc.setRect(rect.x(),rect.y(),rect.width(),rect.height());
move(rc.x(),rc.y() - 3);
if(rect.y() + rect.height() < 40)
hideTimer->stop();
}
void Box::showSlot()
{
rect = this->geometry();
rc.setRect(rect.x(),rect.y(),rect.width(),rect.height());
move(rc.x(), rc.y() + 1.5);
if(rect.y() > 0)
showTimer->stop();
}
为什么收起和显示的速度随着操作次数的增多越来越快,求解。