鼠标界面的隐藏显示

在一次项目中需要实现将鼠标移入窗口范围显示窗口,移出窗口自动隐藏窗口效果
首先需要定义两个动画对象
///
/// 实现动画效果
///
QPropertyAnimation* m_propertyAnimation; 进入
QPropertyAnimation* m_propertyAnimation2; 离开动画
bool eventFilter(QObject* watched, QEvent* event);

在初始化函数中定义如下
QDesktopWidget* desktop = QApplication::desktop();
QRect screenGeometry = desktop->screenGeometry(); ///获取屏幕矩形区域
//
this->setGeometry(screenGeometry.x() + screenGeometry.width()/2-50, screenGeometry.y(), 100, 20); 定义位置在屏幕中间的上面
//setStyleSheet(“background-color: rgba(10, 10, 150, 0.5);”); // 设置背景颜色的透明度为0.5
m_propertyAnimation = new QPropertyAnimation(this, “geometry”);
m_propertyAnimation->setEasingCurve(QEasingCurve::InOutSine);
m_propertyAnimation->setDuration(800);

m_propertyAnimation2 = new QPropertyAnimation(this, "geometry");
m_propertyAnimation2->setEasingCurve(QEasingCurve::InOutSine);
m_propertyAnimation2->setDuration(800);

定义动画路径
m_propertyAnimation->setStartValue(QRect(screenGeometry.x() + screenGeometry.width() / 2 - 50, screenGeometry.y()-40, 100, 20));
m_propertyAnimation->setEndValue(QRect(screenGeometry.x() + screenGeometry.width() / 2 - 50, screenGeometry.y(), 100, 20));

m_propertyAnimation2->setStartValue(QRect(screenGeometry.x() + screenGeometry.width() / 2 - 50, screenGeometry.y(), 100, 20));
m_propertyAnimation2->setEndValue(QRect(screenGeometry.x() + screenGeometry.width() / 2 - 50, screenGeometry.y() - 40, 100, 20));
this->installEventFilter(this);  ///添加事件

下面是对鼠标事件的响应部分
bool Autorun::eventFilter(QObject* watched, QEvent* event)
{
if (event->type() == QEvent::Enter)
{
m_propertyAnimation->start();
return true;
}
else if (event->type() == QEvent::Leave)
{
m_propertyAnimation2->start();
return true;
}

}
这样一个简单的自动显示隐藏的窗口效果就实现了,简单吧

相关推荐

  1. 鼠标界面隐藏显示

    2024-05-01 08:38:01       8 阅读
  2. Android 软键盘显示隐藏

    2024-05-01 08:38:01       36 阅读
  3. css元素隐藏显示

    2024-05-01 08:38:01       26 阅读
  4. layui实现鼠标移入/移出时显示/隐藏tips

    2024-05-01 08:38:01       7 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-05-01 08:38:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-01 08:38:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-01 08:38:01       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-01 08:38:01       20 阅读

热门阅读

  1. 安卓手机APP开发__媒体开发部分__媒体投屏

    2024-05-01 08:38:01       14 阅读
  2. 【Spring】4.Spring的事务管理解析

    2024-05-01 08:38:01       10 阅读
  3. 学习 Rust 的第十五天:如何处理程序异常信息

    2024-05-01 08:38:01       11 阅读
  4. ThinkPHP8 导出Excel数据表格

    2024-05-01 08:38:01       11 阅读
  5. vue3中 使用vue-types

    2024-05-01 08:38:01       9 阅读
  6. servlet生命周期

    2024-05-01 08:38:01       8 阅读