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);