Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT Bug: Mouse position inaccuracy in macOS Monterey
Forum Updated to NodeBB v4.3 + New Features

QT Bug: Mouse position inaccuracy in macOS Monterey

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 196 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nietao
    wrote on last edited by
    #1

    When the mouse is not moved, press the left mouse button, press the right mouse button correctly, It will cause the coordinate judgment click event to fail. Mac OS 11 is OK.

    void mousePressEvent(event) {
    pressedPoint = event->position();
    }
    void mouseReleaseEvent(event) {
    qDebug() << pressedPoint << event->position();
    qDebug() << (pressedPoint.x() - event->position().x()) << (pressedPoint.y() - event->position().y())
    qDebug() << qFuzzyCompare(pressedPoint.x(), event->position().x()) << qFuzzyCompare(pressedPoint.y(), event->position().y())
    }

    output:
    QPointF(146.678,11.3472) QPointF(146.678 11.3472)
    0 -2.44141e-05
    true false

    solution:

    template<typename T>
    inline static bool equal(T a, T b, int decimals = 6)
    {
    T d = static_cast<T>(pow(10, -decimals));
    return a - b > -d && a - b < d;
    }

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by Kent-Dorfman
      #2

      you do understand that floating point numbers are approximations, right? Never expect floating point math to represent an exact value. Always compare within a properly scaled tolerance range.

      isEqual = abs(a-b) < tolerance;

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved