qt 实现停靠窗口 效果
来源:互联网 发布:淘宝整点聚秒杀神器 编辑:程序博客网 时间:2024/05/18 05:23
我创建了一个class继承QWidget,实现enterEvent和leaveEvent两个函数,我实现的效果是这样,一开始这个窗口显示出来,但只显示一半,就是move(-width/2),一旦有鼠标进入的消息,就起个timeline去一点儿一点儿的向右move,直到全都显示出来。
效果就是一个窗口,启动时屏幕只显示一半的的窗口,鼠标进入后就慢慢的全显示出来,鼠标离开后,又慢慢的向左缩到一半显示,类似停靠窗口的概念,这样是OK的,但是问题来了,
这是从左往右慢慢显示的,是没问题,当我从右往左显示的时候就出问题了。
现象是,开始在屏幕右边显示一半的窗口,当鼠标进入窗口时,会进入enterEvent消息,这时候窗口往左move,但这时move完就会马上进入leaveEvent事件,但是这个move执行完时,鼠标依然是在窗口上的,为什么会进入leaveEvent事件呢?这个我很奇怪。
初始化:
this->setFixedSize(50, 60);//设置窗口大小
mTimerEnter = new QTimeLine(500, this);
mTimerEnter->setFrameRange(0,w/2);//max value
mTimerEnter->setCurveShape(QTimeLine::LinearCurve);
mTimerEnter->setEasingCurve(QEasingCurve::OutCubic);
mTimerEnter->setUpdateInterval(20);//step
connect(mTimerEnter, SIGNAL(frameChanged(int)), this, SLOT(showWindowAnimation(int)));
mTimerLeave = new QTimeLine(500, this);
mTimerLeave->setFrameRange(0,w/2);//max value
mTimerLeave->setCurveShape(QTimeLine::LinearCurve);
mTimerLeave->setEasingCurve(QEasingCurve::OutCubic);
mTimerLeave->setUpdateInterval(20);//step
connect(mTimerLeave, SIGNAL(frameChanged(int)), this, SLOT(hideWindowAnimation(int)));
动画绘制:
void DocWindow::showWindowAnimation(int value)
{
int w = this->size().width();
int screen_width = QApplication::desktop()->width();
qDebug() << "showWindowAnimation value:" << value <<"screen_width:"<< screen_width;
if(g_im_setting_param.nPanel_hidetype == HIDE_TO_LEFT)
{
this->move(-w/2+value-OFFSET, 100);
}
else if( g_im_setting_param.nPanel_hidetype == HIDE_TO_RIGTH )
{
this->move(screen_width-value, 100);
}
}
void DocWindow::hideWindowAnimation(int value)
{
int w = this->size().width();
qDebug() << "hideWindowAnimation value:" << value;
if(g_im_setting_param.nPanel_hidetype == HIDE_TO_LEFT)
{
this->move(-value-OFFSET, 100);
this->move(-value-OFFSET, 100);
}
else if( g_im_setting_param.nPanel_hidetype == HIDE_TO_RIGTH )
{
int screen_width = QApplication::desktop()->width();
this->move(screen_width-w+value, 100);
}
}
事件:
void DocWindow::enterEvent(QEvent *event)
{
qDebug() << "DocWindow enterEvent";
if(mTimerEnter->state() == QTimeLine::Running)
{
mTimerEnter->stop();
}
if(mTimerLeave->state() == QTimeLine::Running)
{
mTimerLeave->stop();
}
mTimerEnter->start();
return QWidget::enterEvent(event) ;
}
void DocWindow::leaveEvent(QEvent *event)
{
qDebug() << "DocWindow leaveEvent";
if(mTimerEnter->state() == QTimeLine::Running)
{
mTimerEnter->stop();
}
if(mTimerLeave->state() == QTimeLine::Running)
{
mTimerLeave->stop();
}
mTimerLeave->start();
return QWidget::leaveEvent(event) ;
效果就是一个窗口,启动时屏幕只显示一半的的窗口,鼠标进入后就慢慢的全显示出来,鼠标离开后,又慢慢的向左缩到一半显示,类似停靠窗口的概念,这样是OK的,但是问题来了,
这是从左往右慢慢显示的,是没问题,当我从右往左显示的时候就出问题了。
现象是,开始在屏幕右边显示一半的窗口,当鼠标进入窗口时,会进入enterEvent消息,这时候窗口往左move,但这时move完就会马上进入leaveEvent事件,但是这个move执行完时,鼠标依然是在窗口上的,为什么会进入leaveEvent事件呢?这个我很奇怪。
初始化:
this->setFixedSize(50, 60);//设置窗口大小
mTimerEnter = new QTimeLine(500, this);
mTimerEnter->setFrameRange(0,w/2);//max value
mTimerEnter->setCurveShape(QTimeLine::LinearCurve);
mTimerEnter->setEasingCurve(QEasingCurve::OutCubic);
mTimerEnter->setUpdateInterval(20);//step
connect(mTimerEnter, SIGNAL(frameChanged(int)), this, SLOT(showWindowAnimation(int)));
mTimerLeave = new QTimeLine(500, this);
mTimerLeave->setFrameRange(0,w/2);//max value
mTimerLeave->setCurveShape(QTimeLine::LinearCurve);
mTimerLeave->setEasingCurve(QEasingCurve::OutCubic);
mTimerLeave->setUpdateInterval(20);//step
connect(mTimerLeave, SIGNAL(frameChanged(int)), this, SLOT(hideWindowAnimation(int)));
动画绘制:
void DocWindow::showWindowAnimation(int value)
{
int w = this->size().width();
int screen_width = QApplication::desktop()->width();
qDebug() << "showWindowAnimation value:" << value <<"screen_width:"<< screen_width;
if(g_im_setting_param.nPanel_hidetype == HIDE_TO_LEFT)
{
this->move(-w/2+value-OFFSET, 100);
}
else if( g_im_setting_param.nPanel_hidetype == HIDE_TO_RIGTH )
{
this->move(screen_width-value, 100);
}
}
void DocWindow::hideWindowAnimation(int value)
{
int w = this->size().width();
qDebug() << "hideWindowAnimation value:" << value;
if(g_im_setting_param.nPanel_hidetype == HIDE_TO_LEFT)
{
this->move(-value-OFFSET, 100);
this->move(-value-OFFSET, 100);
}
else if( g_im_setting_param.nPanel_hidetype == HIDE_TO_RIGTH )
{
int screen_width = QApplication::desktop()->width();
this->move(screen_width-w+value, 100);
}
}
事件:
void DocWindow::enterEvent(QEvent *event)
{
qDebug() << "DocWindow enterEvent";
if(mTimerEnter->state() == QTimeLine::Running)
{
mTimerEnter->stop();
}
if(mTimerLeave->state() == QTimeLine::Running)
{
mTimerLeave->stop();
}
mTimerEnter->start();
return QWidget::enterEvent(event) ;
}
void DocWindow::leaveEvent(QEvent *event)
{
qDebug() << "DocWindow leaveEvent";
if(mTimerEnter->state() == QTimeLine::Running)
{
mTimerEnter->stop();
}
if(mTimerLeave->state() == QTimeLine::Running)
{
mTimerLeave->stop();
}
mTimerLeave->start();
return QWidget::leaveEvent(event) ;
}
解决了,是鼠标刚进入窗口的时候,动画绘制的坐标错误,
this->move(screen_width-value, 100);第一次value是0.也就是说,一上来就移出去了。
0 0
- qt 实现停靠窗口 效果
- QT主窗口的停靠窗口实现
- QT主窗口的停靠窗口实现
- QT主窗口的停靠窗口实现
- Qt中停靠窗口的实现
- Qt中停靠窗口的实现
- Qt中停靠窗口的实现
- Delphi7 窗口停靠效果
- Qt停靠窗口
- QT--QDockWidget 停靠窗口
- JQUERY 实现窗口滚动搜索框停靠效果
- Qt 布局管理 - 停靠窗口
- Qt 布局管理 - 停靠窗口
- 自学QT之停靠窗口
- QT窗口停靠使用案例
- Qt停靠窗口角落设置
- Qt停靠窗口QDockWidget应用
- QT窗口布局-停靠窗口类QDockWidget
- PHP + Ice安装配置
- Android sqlite 数据库操作
- 追踪调用
- 用表情开发“俏皮”编程语言
- MAT分析JAVA内存问题
- qt 实现停靠窗口 效果
- spring整合junit单元测试
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
- 脏读、不可重复读、幻读以及事务的五种隔离级别
- jdbc使用事务隔离
- 奖学金文章更新 连载6第六篇 陈元威 海南IOS第一期学员
- java.lang.String的substring、split方法引起的内存问题
- OJ——对象数组求最大值
- hibernate 配置 扫描实体类