首页 >> 大全

QT 鼠标移到按钮上,就弹出对话框,移开,对话框就消失

2023-08-21 大全 31 作者:考证青年

我们在做项目的时候,有一个这样的需求,就是一个按钮鼠标放上去之后,就会弹出一张图片,鼠标移开,图片就消失。

比如这样的按钮,

鼠标放上去之后,就会弹出对话框

js弹出下载框__点击登录弹出登录框

js弹出下载框__点击登录弹出登录框

该怎么做呢?

其中,

1.那个带图标的按钮, 其实是个, 可以设置前面图标,后面文字。

2.使用 显示图片

js弹出下载框_点击登录弹出登录框_

    m_pStandardLabel = new QLabel(this);QPixmap pixmap(qApp->applicationDirPath() + "/scoreStandard.png");m_pStandardLabel->setPixmap(pixmap);m_pStandardLabel->resize(619, 471);m_pStandardLabel->hide();

3.安装事件过滤器(需要给 和显示图片的都要安装)

    ui->scoreStandardBtn->installEventFilter(this);m_pStandardLabel->installEventFilter(this);

4.重写事件过滤器

bool eventFilter(QObject *watched, QEvent *event);

bool QcTaskDetailForm::eventFilter(QObject *watched, QEvent *event)
{if(ui->scoreStandardBtn == watched || m_pStandardLabel == watched) {if(QEvent::Enter == event->type()) {            //鼠标进入if (m_pStandardLabel->isHidden()) { //已经隐藏就显示出来m_pStandardLabel->show();QPoint point = ui->scoreStandardBtn->pos();point.rx() = point.x() -  m_pStandardLabel->width() + 120;point.ry() = point.y() + ui->scoreStandardBtn->height() + 40;m_pStandardLabel->move(point);m_pStandardLabel->raise();//显示最顶层return true;}}else if (QEvent::Leave == event->type()) { //鼠标离开if (!m_pStandardLabel->isHidden()) {if(!ui->scoreStandardBtn->geometry().contains(this->mapFromGlobal(QCursor::pos())) //判断鼠标是否在控件上&&!m_pStandardLabel->geometry().contains(this->mapFromGlobal(QCursor::pos())) ){m_pStandardLabel->hide();return true;}}}}return QWidget::eventFilter(watched, event);
}

关于我们

最火推荐

小编推荐

联系我们


版权声明:本站内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 88@qq.com 举报,一经查实,本站将立刻删除。备案号:桂ICP备2021009421号
Powered By Z-BlogPHP.
复制成功
微信号:
我知道了