Qt 之 QQ系统表情—实现动态显示效果
2016-09-26 22:15
363 查看
简述
在Qt 之 QQ系统表情(五) 中 我们实现了自定义系统表情窗口,这一篇将简单介绍如何实现QQ聊天界面中小表情窗口切换至正常表情窗口的动画效果。先看看QQ的效果:
当鼠标悬浮在表情按钮之上显示小表情窗口,点击动态显示正常表情窗口,再点击隐藏窗口。表面上看起来这几个动作很简单,但是要想控制好着实不易,下面直接上代码。
代码之路
//显示小窗口 void EmotionWindow::showSmallEmotion(QPoint point) { m_normalEmotionWidget->setVisible(false); m_smallEmotionWidget->setVisible(true); m_lableTitle->setText("This is Small Emotion Window"); this->resize(QSize(m_smallEmotionWidget->width() + 20, m_smallEmotionWidget->height() + 50)); move(point.x() - width() / 2, point.y() - height()); show(); activateWindow(); } //从小窗口变换至大窗口效果显示 void EmotionWindow::showNormalEmotion(QPoint point) { //将小表情窗口和文字提示隐藏 m_lableTitle->setVisible(false); m_smallEmotionWidget->setVisible(false); show(); activateWindow(); //动画显示 QPropertyAnimation *pAnimation = new QPropertyAnimation(this, "geometry"); QPoint startPoint(point.x() - width() / 2, point.y() - height()); QPoint endPoint(point.x() - m_normalEmotionWidget->width() / 2, point.y() - m_normalEmotionWidget->height() - 50); // 动画显示时长 pAnimation->setDuration(200); // 窗口变换起始尺寸 pAnimation->setStartValue(QRect(startPoint.x(), startPoint.y(), width(), height())); // 窗口变换结束尺寸 pAnimation->setEndValue(QRect(endPoint.x(), endPoint.y(), m_normalEmotionWidget->width() + 20, m_normalEmotionWidget->height() + 50)); // 变换效果类型 pAnimation->setEasingCurve(QEasingCurve::Linear); pAnimation->start(QAbstractAnimation::DeleteWhenStopped); // 动画效果显示结束显示正常的窗口 connect(pAnimation, SIGNAL(finished()), this, SLOT(onAnimationFinished())); } //动画显示结束,显示正常的窗口 void EmotionWindow::onAnimationFinished() { m_lableTitle->setVisible(true); m_normalEmotionWidget->setVisible(true); m_lableTitle->setText("This is Normal Emotion Window"); } bool EmotionWindow::eventFilter(QObject *obj, QEvent *event) { // 调用activeWindow()方法后进入 if (QEvent::WindowActivate == event->type()) { qDebug() << "WindowActivate_____________"; } // 窗口失去焦点后进入(这里用来当鼠标点击表情窗口外的其他部分自动隐藏表情窗口) else if (QEvent::WindowDeactivate == event->type()) { this->hide(); qDebug() << "WindowDeactivate___________"; } return __super::eventFilter(obj , event); }
看一下效果图:
以上给出了关键的几个方法,具体鼠标点击按钮、悬浮在按钮上等显示不同的窗口由于还存在一些小问题,暂不给出具体实现,在下一篇中将完善实现完整效果,敬请期待!
尾
——掐指一算,已经20天没有更新博客了,这20天说忙也忙,说不忙也不忙。时间永远都是海绵中的水,还是在于自己的掌控。Keep Coding , Keep Moving —— Every Day !相关文章推荐
- qt实现的窗口吸附屏幕边缘,动画隐藏显示的效果,类似于qq主窗口 吸附 隐藏的效果
- QT实现动态显示系统时间
- 鼠标缩略图遥感图像显示时的连动效果——Qt实现
- 关于jquery解析json数据时动态追加tr 指定条数换行问题 实现list的 并列显示效果
- Jquery实现动态效果的显示和隐藏控件
- qt动态显示当前时间如何实现
- [QT]QT教程之实例分析[三] 实现QQ抽屉效果(QToolBox 和QToolButton)
- 动态实现客户端系统时间的显示
- qt程序实现多个图片连续显示效果像动画一样
- 用src属性动态替换图片;图片预加载---鼠标事件实现图片翻转效果;随机显示图片和onClick事件
- ngui 实现聊天系统中玩家输入表情与文字结合显示
- richTextBox如何实现输入指定的字符显示一个表情图标?类似QQ那样?
- jquery+ajax实现倒计时动态显示效果。
- 基于jquery的多彩百分比 动态进度条 投票效果显示效果实现代码
- 怎么用Java实现QQ消息输入框这种能表情图片和文字混排的效果
- QT学习 第一章:基本对话框--实现QQ抽屉效果
- Java 程序设计 利用线程实现动态显示系统时间
- [QT]QT教程之实例分析[三] 实现QQ抽屉效果(QToolBox 和QToolButton)
- 向Richedit插入动态Gif的实现(关于QQ表情功能的制作)
- 巧用内置函数+句柄实现:动态显示窗体效果