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. Mouse position issue
Forum Updated to NodeBB v4.3 + New Features

Mouse position issue

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 332 Views 2 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by Perdrix
    #1

    I have some code in a paint function that reads:

    const QPoint globalMouseLocation(QCursor::pos());
    const QPointF mouseLocation(mapFromGlobal(globalMouseLocation));
    
    // If the mouse is not over the image , then there's nothing to do
    if (!displayRect.contains(mouseLocation)) return;
    

    which works fine when the mouse is moved within the widget - it returns when it's not over displayRect.

    If the mouse is moved from being over the area defined by displayRect to being over another widget/window (i.e. when displayRect extends right to the edge of the widget), then the mouse position reported is still shown is being in displayRect when in fact the mouse is over another control entirely.

    What to I need to do so that I can detect its no longer over displayRect in that case.

    Will making the relevant change to fix this have any unexpected side effects?

    sierdzioS 1 Reply Last reply
    0
    • sierdzioS sierdzio

      @Perdrix maybe a bit hacky, but you can try flipping the logic on it's head: map the displayRect to global coordinates (by mapping its top left corner) and then check if global mouse position is within the rect.

      PerdrixP Offline
      PerdrixP Offline
      Perdrix
      wrote on last edited by
      #3

      @sierdzio I changed the if statement to read:

      if (!underMouse() || !displayRect.contains(mouseLocation)) return;

      and added an update() call to the leaveEvent() handler.

      Problem solved.

      1 Reply Last reply
      0
      • PerdrixP Perdrix

        I have some code in a paint function that reads:

        const QPoint globalMouseLocation(QCursor::pos());
        const QPointF mouseLocation(mapFromGlobal(globalMouseLocation));
        
        // If the mouse is not over the image , then there's nothing to do
        if (!displayRect.contains(mouseLocation)) return;
        

        which works fine when the mouse is moved within the widget - it returns when it's not over displayRect.

        If the mouse is moved from being over the area defined by displayRect to being over another widget/window (i.e. when displayRect extends right to the edge of the widget), then the mouse position reported is still shown is being in displayRect when in fact the mouse is over another control entirely.

        What to I need to do so that I can detect its no longer over displayRect in that case.

        Will making the relevant change to fix this have any unexpected side effects?

        sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #2

        @Perdrix maybe a bit hacky, but you can try flipping the logic on it's head: map the displayRect to global coordinates (by mapping its top left corner) and then check if global mouse position is within the rect.

        (Z(:^

        PerdrixP 1 Reply Last reply
        0
        • sierdzioS sierdzio

          @Perdrix maybe a bit hacky, but you can try flipping the logic on it's head: map the displayRect to global coordinates (by mapping its top left corner) and then check if global mouse position is within the rect.

          PerdrixP Offline
          PerdrixP Offline
          Perdrix
          wrote on last edited by
          #3

          @sierdzio I changed the if statement to read:

          if (!underMouse() || !displayRect.contains(mouseLocation)) return;

          and added an update() call to the leaveEvent() handler.

          Problem solved.

          1 Reply Last reply
          0
          • PerdrixP Perdrix has marked this topic as solved on

          • Login

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