Skip to content

Commit

Permalink
Merge pull request Framstag#1603 from janbar/fix_touch_event_qt6
Browse files Browse the repository at this point in the history
final fix for screen touch/pointer event with qt6
  • Loading branch information
Framstag authored Sep 17, 2024
2 parents 5f4394d + bb0794e commit 9410226
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions libosmscout-client-qt/src/osmscoutclientqt/MapWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ MapWidget::MapWidget(QQuickItem* parent)
setOpaquePainting(true);
setAcceptedMouseButtons(Qt::LeftButton);
setAcceptHoverEvents(true);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
setAcceptTouchEvents(true);
#endif

renderer = OSMScoutQt::GetInstance().MakeMapRenderer(renderingType);
auto settings=OSMScoutQt::GetInstance().GetSettings();
Expand Down Expand Up @@ -101,24 +104,21 @@ void MapWidget::translateToTouch(QMouseEvent* event, Qt::TouchPointStates states
{
assert(event);

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
// translate the mouse event for desktop device without touch pointer
QTouchEvent touchEvnt(QEvent::TouchBegin, event->pointingDevice(), Qt::NoModifier, event->points());
#else
QTouchEvent::TouchPoint touchPoint;
touchPoint.setPressure(1);
touchPoint.setPos(event->pos());
touchPoint.setState(states);
QList<QTouchEvent::TouchPoint> points;
points << touchPoint;
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QTouchEvent touchEvnt(QEvent::TouchBegin, 0, Qt::NoModifier, 0, points);
#else
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QTouchEvent touchEvnt(QEvent::TouchBegin, 0, Qt::NoModifier, Qt::TouchPointStates(), points);
#endif
#else
// TODO: rework
// 6.7.2: CTOR QEventPoint fails to initialize the position, so pass directly event points
// 6.7.2: Without passing a valid pointer to device, it will crash later on released event by
// calling QQuickWindowPrivate::clearGrabbers >> QPointerEvent::setExclusiveGrabber
QTouchEvent touchEvnt(QEvent::TouchBegin, event->pointingDevice(), Qt::NoModifier, event->points());
QTouchEvent touchEvnt(QEvent::TouchBegin, 0, Qt::NoModifier, 0, points);
#endif
#endif

//qDebug() << "translate mouse event to touch event: "<< touchEvnt;
Expand Down

0 comments on commit 9410226

Please sign in to comment.