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. Random MousePressOffset

Random MousePressOffset

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 404 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.
  • J.HilkJ Offline
    J.HilkJ Offline
    J.Hilk
    Moderators
    wrote on last edited by
    #1

    Hello,

    I recently run into a problem using QMouseEvent - Press, Release and Move.

    In the end I was able to fix it, but I'm puzzled, why this was a problem in the first place. Maybe someone can enlighten me on what is going on.

    Ok, the MousePress Origin was saved like this:

    mousePressEvent(QMouseEvent *event){
       pointPressed = event->pos();
    }
    

    In mouse move I had the following:

    mouseMoveEvent(QMouseEvent *event){
       int distY = pointPressed.y() - event->y();
       this->move(this->x(),0-distY);
    }
    

    For fast mousemoves, everything works fine, for slow movement of the mouse however, the widgets gets 'stuttery'. It jumps back and forth.

    Turns out, pointPressed actually chages its value by 1, even so mousebutton is not pressed again. Found with

    qDebug() << pointPressed; //In mouseMoveEvent
    

    fixed it with the following:

    //MousePressEvent
    pointPressed = mapToGlobal(event->pos());
    
    //mouseMoveEvent
    QPoint eveGl = mapToGlobal(event->pos());
    int distY = pointPressed.y() - eveGl.y();
    

    By the way, pointPressed = mapToGlobal(event->pos()); has to happen in MousePressEvent . If I do both maptoGlobals in the mouseMoveEvent I have the same behaviour as if I used local coordinates.

    If any one could explain that to me, I would be very grateful.


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    1 Reply Last reply
    0
    • J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      Turns out @kragnfrol answered my question. Probably without knowladge of this topics existence x)

      from the definition of QPoint QMouseEvent::pos() const

      Those who are able to read are at an advantage indeed...


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      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