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. MouseMoveEvent() how to set the refresh interval?
Forum Updated to NodeBB v4.3 + New Features

MouseMoveEvent() how to set the refresh interval?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 5.7k 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.
  • A Offline
    A Offline
    andrea993.93
    wrote on last edited by
    #1

    Hi all,
    I'm developing an application that makes a lot of operations at the same time.

    When the function mouseMoveEvent() of my principal widget is called, the application slows too while I move the mouse.

    This application should not request a continuous refresh of the mouse position but the refresh can be done also 1 time on 10 so the slowdowns should disappear.

    How can I do it?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      I know of no way to throttle the interval.

      Perhaps you can decouple the processing from the move event itself by using the move event to update an X/Y coordinate pair in your class, and then doing your data processing periodically via a QTimer. If you don't need to constantly redo the operations, additionally set a boolean flag to true when the coordinates are updated then have your timeout slot check to see if that flag has been set before attempting to do your processing on the most recent mouse coordinates (and then clear the flag.)

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andrea993.93
        wrote on last edited by
        #3

        It's a good idea but how can I do to read the mouse current position only when I want?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          You don't. You make your mouseMoveEvent very lightweight. And all it does is store the x and y position of the mouse in a couple of private variables. Then you can read those variables whenever you wish.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andrea993.93
            wrote on last edited by
            #5

            I think my mousemoveevent is already lightweight because the if condtions are rarely satisfied:
            @void MatrixW::mouseMoveEvent(QMouseEvent *e)
            {
            if(thismove!=none)
            {
            int xnew=e->x()/larghcell;
            int ynew =e->y()/altcell;

                if((xnew!=xN||ynew!=yN)&&(xnew<size_x && ynew<size_y))
                {
                    if (isarelease)
                    {
                        isarelease=false;
                        
                        if (thismove==del)
                           setcell(xN,yN,0);
                        else if (thismove==add)
                           setcell(xN,yN,1);
                    }
            
                    xN=xnew;
                    yN=ynew;
            
                    if (thismove==del)
                      setcell(xN,yN,0);
                    else if (thismove==add)
                      setcell(xN,yN,1);
            
                    update();
                }
            }
            

            }@

            (thismove!=none) only if the mouse is clicked
            ((xnew!=xN||ynew!=yN)&&(xnew<size_x && ynew<size_y)) is rarely true each 50-100 ms

            The good way to do this I think is to start a timer when the mouse was clicked, the timer call each 50-100ms a function like MatrixW::mouseMoveEvent(QMouseEvent *e) where the program can read the muose position.
            The mouse release event stop the timer.

            But I don't know how to read the mouse position in the function called by the timer

            continually read the mouse position would be the same as what I do now (about the slowdowns)

            1 Reply Last reply
            0

            • Login

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