fix: 修复bug84892

Description: 重写了鼠标事件,现在已经正常显示鼠标

Log: 与视图有关
Bug: https://pms.uniontech.com/zentao/bug-view-84892.html
Change-Id: Icd4bf87c07a83f860fbc0350e7095e0af491b927
This commit is contained in:
liuminghang 2021-06-24 20:45:02 +08:00
parent a9c3013e9f
commit 902758fd49
2 changed files with 24 additions and 2 deletions

View File

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

View File

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