麒麟系统下鼠标进入弹窗失去焦点focus自动隐藏
麒麟系统下鼠标进入届满后触发enterevent,显示弹窗,展示状态
鼠标进入按钮,触发消息显示状态界面
connect(pCase, &CaseItem::signalShowCaseState, this, [=](TasksStatistic taskState) { m_CaseStateWidget.SetTasksStatistic(taskState); QPoint Point = QCursor::pos(); m_CaseStateWidget.move(Point.x() + 10, Point.y() + 10); m_CaseStateWidget.hide();//先隐藏再显示,否则会出现在下面; m_CaseStateWidget.show(); m_CaseStateWidget.setFocus(Qt::FocusReason::ActiveWindowFocusReason);//单击其他位置会触发失去焦点函数,自动隐藏 });
状态显示界面定义
#include "CaseStateWidget.h" #pragma execution_character_set("utf-8") CaseStateWidget::CaseStateWidget(QWidget *parent) : QWidget(parent) { ui.setupUi(this); setWindowFlags(Qt::FramelessWindowHint); connect(ui.pushButton, &QPushButton::clicked, this, [=]() { emit signalShowFailedTask(m_taskstatistic.failedTask); hide(); }); } CaseStateWidget::~CaseStateWidget() { } void CaseStateWidget::SetTasksStatistic(TasksStatistic& taskstatistic) { m_taskstatistic = taskstatistic; ui.labelAll->setText(QString(" 共%1个视频任务").arg(taskstatistic.finished+ taskstatistic.unfinished)); ui.labelFailed->setText(QString("已失败%1个").arg(taskstatistic.failed)); ui.labelFinished->setText(QString("已完成%1个").arg(taskstatistic.finished)); if (taskstatistic.failed==0) { ui.pushButton->hide(); } else { ui.pushButton->show(); } } void CaseStateWidget::focusOutEvent(QFocusEvent *event) { hide(); } void CaseStateWidget::leaveEvent(QEvent *event) { hide(); }
进入自定义按钮的响应函数
#include "CaseStateButton.h" CaseStateButton::CaseStateButton(QWidget *parent) : QPushButton(parent) { } CaseStateButton::~CaseStateButton() { } void CaseStateButton::enterEvent(QEvent *event) { emit signalShowStateWidget(true); } void CaseStateButton::leaveEvent(QEvent *event) { emit signalShowStateWidget(false); }
自己开发了一个股票智能分析软件,功能很强大,需要的关注微信公众号:QStockView