From 902758fd49c37cb36f6dcc3ec3cb1fdc6c1cc31f Mon Sep 17 00:00:00 2001 From: liuminghang Date: Thu, 24 Jun 2021 20:45:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dbug84892?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 重写了鼠标事件,现在已经正常显示鼠标 Log: 与视图有关 Bug: https://pms.uniontech.com/zentao/bug-view-84892.html Change-Id: Icd4bf87c07a83f860fbc0350e7095e0af491b927 --- src/view/imageview.cpp | 22 +++++++++++++++++++++- src/view/imageview.h | 4 +++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/view/imageview.cpp b/src/view/imageview.cpp index 4f03cc3..c2e619b 100644 --- a/src/view/imageview.cpp +++ b/src/view/imageview.cpp @@ -27,6 +27,7 @@ ImageView::ImageView(QWidget *parent): setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); this->grabGesture(Qt::PinchGesture); setAttribute(Qt::WA_AcceptTouchEvents); + viewport()->setCursor(Qt::ArrowCursor); } void ImageView::openImage(const QString &path) @@ -191,9 +192,28 @@ void ImageView::autoFit() } +void ImageView::mouseReleaseEvent(QMouseEvent *e) +{ + QGraphicsView::mouseReleaseEvent(e); + viewport()->setCursor(Qt::ArrowCursor); +} + +void ImageView::mousePressEvent(QMouseEvent *e) +{ + QGraphicsView::mousePressEvent(e); + viewport()->unsetCursor(); + viewport()->setCursor(Qt::ArrowCursor); +} + void ImageView::mouseMoveEvent(QMouseEvent *event) { - return QGraphicsView::mouseMoveEvent(event); + //修复鼠标状态不对的问题 + if (!(event->buttons() | Qt::NoButton)) { + viewport()->setCursor(Qt::ArrowCursor); + } else { + QGraphicsView::mouseMoveEvent(event); + viewport()->setCursor(Qt::ClosedHandCursor); + } } bool ImageView::event(QEvent *event) diff --git a/src/view/imageview.h b/src/view/imageview.h index 0dad3e7..abddecf 100644 --- a/src/view/imageview.h +++ b/src/view/imageview.h @@ -26,7 +26,9 @@ public: //自适应窗口 void autoFit(); //鼠标移动事件 - void mouseMoveEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; bool event(QEvent *event)override; bool gestureEvent(QGestureEvent *event);