本文主要是介绍全屏晃动鼠标显示控制栏,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
setMouseTracking(true) 就能解决?从来没有成功过。
发现 https://github.com/xymov/vst-video 有这种操作,仔细阅读源码,发现要配合 eventFilter 使用!
基本实现功能,但是晃动不太灵敏,不知道为什么。
mainwindow.hprotected:bool eventFilter(QObject *obj, QEvent *event) override;private:QTimer *timer_controlPanel;mainwindow.cpp
{timer_controlPanel = new QTimer;timer_controlPanel->setSingleShot(true);connect(timer_controlPanel, &QTimer::timeout, [=]{if(isFullScreen()){ui->sliderProgress->hide();ui->controlPanel->hide();setCursor(Qt::BlankCursor);}});ui->graphicsView->installEventFilter(this);ui->controlPanel->installEventFilter(this);
}bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{if(obj == ui->graphicsView){if (event->type() == QEvent::MouseMove) { //晃动显示并开始计时if(isFullScreen()){setCursor(Qt::ArrowCursor);ui->sliderProgress->show();ui->controlPanel->show();timer_controlPanel->start(3000);}return true;}} else if (obj == ui->controlPanel) {if (event->type() == QEvent::Enter) { //进入停止计时timer_controlPanel->stop();} else if (event->type() == QEvent::Leave) { //离开开始计时timer_controlPanel->start(3000);}} else {return QObject::eventFilter(obj, event);}
}
这篇关于全屏晃动鼠标显示控制栏的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!