From 9bf2eb48075f27477850024c295f54e0e3a87459 Mon Sep 17 00:00:00 2001 From: xiaoming <2014500726@smail.xtu.edu.cn> Date: Fri, 9 Jun 2023 10:30:34 +0800 Subject: [PATCH] src:update view windows code Signed-off-by: xiaoming <2014500726@smail.xtu.edu.cn> --- src/ImgViewer.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/ImgViewer.cpp b/src/ImgViewer.cpp index 7bf4d43..f7accf0 100644 --- a/src/ImgViewer.cpp +++ b/src/ImgViewer.cpp @@ -255,6 +255,13 @@ void ImgViewer::mouseDoubleClickEvent(QMouseEvent *event) { } void ImgViewer::wheelEvent(QWheelEvent *event) { + #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + double event_x=event->position().x(); + double event_y=event->position().y(); + #else + double event_x=event->x(); + double event_y=event->y(); + #endif if (!this->img_list.empty()) { if( event->angleDelta().y() > 0) { // 放大图片 @@ -265,10 +272,10 @@ void ImgViewer::wheelEvent(QWheelEvent *event) { currentImg2scaledImg(this->currentImg,this->scaled_img, QSize(this->scaled_img.width() + setpsize_x,this->scaled_img.height() + setpsize_y)); - float new_w = event->position().x() - - (this->scaled_img.width() * (event->position().x() - this->point.x())) / (this->scaled_img.width() - setpsize_x); - float new_h = event->position().y() - - (this->scaled_img.height() * (event->position().y() - this->point.y())) / (this->scaled_img.height() - setpsize_y); + float new_w = event_x - + (this->scaled_img.width() * (event_x - this->point.x())) / (this->scaled_img.width() - setpsize_x); + float new_h = event_y - + (this->scaled_img.height() * (event_y - this->point.y())) / (this->scaled_img.height() - setpsize_y); this->point = QPoint(new_w, new_h); this->repaint(); } @@ -281,10 +288,10 @@ void ImgViewer::wheelEvent(QWheelEvent *event) { currentImg2scaledImg(this->currentImg,this->scaled_img, QSize(this->scaled_img.width() - setpsize_x,this->scaled_img.height() - setpsize_y)); - float new_w = event->position().x() - - (this->scaled_img.width() * (event->position().x() - this->point.x())) / (this->scaled_img.width() + setpsize_x); - float new_h = event->position().y() - - (this->scaled_img.height() * (event->position().y() - this->point.y())) / (this->scaled_img.height() + setpsize_y); + float new_w = event_x - + (this->scaled_img.width() * (event_x - this->point.x())) / (this->scaled_img.width() + setpsize_x); + float new_h = event_y - + (this->scaled_img.height() * (event_y - this->point.y())) / (this->scaled_img.height() + setpsize_y); this->point = QPoint(new_w, new_h); this->repaint(); }