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. How to increase refresh rate on mouseMoveEvent?
Forum Updated to NodeBB v4.3 + New Features

How to increase refresh rate on mouseMoveEvent?

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 4 Posters 6.3k 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.
  • Y Offline
    Y Offline
    Yippiyak
    wrote on last edited by
    #1

    Hello,
    Like the title says I am designing a UI that incorporates a cross hair that tracks the cursor, but there is significant lag when I move the cursor quickly. I would like to reduce the lag, and I am not sure how. Thank you!

    V 1 Reply Last reply
    0
    • Y Yippiyak

      Hello,
      Like the title says I am designing a UI that incorporates a cross hair that tracks the cursor, but there is significant lag when I move the cursor quickly. I would like to reduce the lag, and I am not sure how. Thank you!

      V Offline
      V Offline
      Violet Giraffe
      wrote on last edited by
      #2

      @Yippiyak
      Are you certain that the lag is related to mouse events and not to drawing the crosshair, for example?

      Y 1 Reply Last reply
      0
      • V Violet Giraffe

        @Yippiyak
        Are you certain that the lag is related to mouse events and not to drawing the crosshair, for example?

        Y Offline
        Y Offline
        Yippiyak
        wrote on last edited by
        #3

        @Violet-Giraffe I am not certain of anything haha. I have a qpainter drawing lines that run to the screen boundaries, but they do not follow the mouse very well at all at high speeds.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Violet Giraffe
          wrote on last edited by
          #4

          Try my sample program. Is it faster than yours or the same?

          #include <QApplication>
          #include <QDesktopWidget>
          #include <QMainWindow>
          #include <QMouseEvent>
          #include <QPainter>
          #include <QPaintEvent>
          
          struct MouseWidget : QWidget {
          	MouseWidget(QWidget* parent) : QWidget(parent) {
          		setMouseTracking(true);
          	}
          
          	void mouseMoveEvent(QMouseEvent* e) override {
          		_mousePos = e->pos();
          		update();
          	}
          
          	void paintEvent(QPaintEvent* /*e*/) override {
          		QPainter p(this);
          		p.drawRect(_mousePos.x(), _mousePos.y(), 20, 20);
          	}
          
          private:
          	QPoint _mousePos;
          };
          
          int main(int argc, char *argv[])
          {
          	QApplication app(argc, argv);
          
          	QMainWindow w;
          	w.resize(qApp->desktop()->screen()->size() / 2);
          	w.setCentralWidget(new MouseWidget(&w));
          	w.show();
          
          	return app.exec();
          }
          
          Y 1 Reply Last reply
          2
          • V Violet Giraffe

            Try my sample program. Is it faster than yours or the same?

            #include <QApplication>
            #include <QDesktopWidget>
            #include <QMainWindow>
            #include <QMouseEvent>
            #include <QPainter>
            #include <QPaintEvent>
            
            struct MouseWidget : QWidget {
            	MouseWidget(QWidget* parent) : QWidget(parent) {
            		setMouseTracking(true);
            	}
            
            	void mouseMoveEvent(QMouseEvent* e) override {
            		_mousePos = e->pos();
            		update();
            	}
            
            	void paintEvent(QPaintEvent* /*e*/) override {
            		QPainter p(this);
            		p.drawRect(_mousePos.x(), _mousePos.y(), 20, 20);
            	}
            
            private:
            	QPoint _mousePos;
            };
            
            int main(int argc, char *argv[])
            {
            	QApplication app(argc, argv);
            
            	QMainWindow w;
            	w.resize(qApp->desktop()->screen()->size() / 2);
            	w.setCentralWidget(new MouseWidget(&w));
            	w.show();
            
            	return app.exec();
            }
            
            Y Offline
            Y Offline
            Yippiyak
            wrote on last edited by Yippiyak
            #5

            @Violet-Giraffe Your's is slightly faster, and it may not be possible, but there is still some lag in what you wrote as well. I am looking for tracking that would have no lag, and essentially be on par with a modern shooter game crosshair.
            Edit: what is the significance of the override command?

            mrjjM 1 Reply Last reply
            0
            • Y Yippiyak

              @Violet-Giraffe Your's is slightly faster, and it may not be possible, but there is still some lag in what you wrote as well. I am looking for tracking that would have no lag, and essentially be on par with a modern shooter game crosshair.
              Edit: what is the significance of the override command?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @Yippiyak
              Hi
              Do you by any way store points/lines while drawing ?
              if yes Can you try the
              http://doc.qt.io/qt-5/qtwidgets-widgets-scribble-example.html
              which uses dirty rect for updating and see if that is faster?

              override just means, "tell me if i dont actually override the virtual function"
              so if u flag something for override and u have wrong signature, compiler will tell you.

              Anyway, if you testing with a usb mouse, it might also just be the actually polling from Os side.
              in win 7 days, i used
              http://www.softpedia.com/get/Tweak/System-Tweak/USB-Mouserate-switcher.shtml
              but i have not tried in window 8+ if it still have any effect.

              Y 1 Reply Last reply
              1
              • mrjjM mrjj

                @Yippiyak
                Hi
                Do you by any way store points/lines while drawing ?
                if yes Can you try the
                http://doc.qt.io/qt-5/qtwidgets-widgets-scribble-example.html
                which uses dirty rect for updating and see if that is faster?

                override just means, "tell me if i dont actually override the virtual function"
                so if u flag something for override and u have wrong signature, compiler will tell you.

                Anyway, if you testing with a usb mouse, it might also just be the actually polling from Os side.
                in win 7 days, i used
                http://www.softpedia.com/get/Tweak/System-Tweak/USB-Mouserate-switcher.shtml
                but i have not tried in window 8+ if it still have any effect.

                Y Offline
                Y Offline
                Yippiyak
                wrote on last edited by
                #7

                @mrjj It is not the USB, but I am running about 1.4 million data points in the background so the the project is slow as a whole haha. Im just trying to see if there is a way to reduce the time necessary to call and update mouseMoveEvent.

                mrjjM 1 Reply Last reply
                0
                • Y Yippiyak

                  @mrjj It is not the USB, but I am running about 1.4 million data points in the background so the the project is slow as a whole haha. Im just trying to see if there is a way to reduce the time necessary to call and update mouseMoveEvent.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Yippiyak
                  ah, so the mouse drawing cross paint event is shared with
                  painting of the the points?

                  1 Reply Last reply
                  0
                  • Y Offline
                    Y Offline
                    Yippiyak
                    wrote on last edited by Yippiyak
                    #9

                    @mrjj
                    No, its threaded and theoretically happens independently. Its just not tracking fast enough.

                    mrjjM 1 Reply Last reply
                    1
                    • Y Yippiyak

                      @mrjj
                      No, its threaded and theoretically happens independently. Its just not tracking fast enough.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Yippiyak
                      Ok. Normally in games they use hardware cursors to avoid this kind of trailing.
                      https://stackoverflow.com/questions/6957039/what-is-hardware-cursor-and-how-does-it-work

                      Im not sure there is a way, to make it go faster. Unless its due to something lagging/stressing the event queue
                      or anything like that.

                      Y 1 Reply Last reply
                      1
                      • mrjjM mrjj

                        @Yippiyak
                        Ok. Normally in games they use hardware cursors to avoid this kind of trailing.
                        https://stackoverflow.com/questions/6957039/what-is-hardware-cursor-and-how-does-it-work

                        Im not sure there is a way, to make it go faster. Unless its due to something lagging/stressing the event queue
                        or anything like that.

                        Y Offline
                        Y Offline
                        Yippiyak
                        wrote on last edited by
                        #11

                        @mrjj
                        Thanks for the tip on the hardware cursor, that may be the approach I need to take anyway in order to boost my programs performance. I am rendering a spectrogram and it is too slow!

                        mrjjM 1 Reply Last reply
                        0
                        • Y Yippiyak

                          @mrjj
                          Thanks for the tip on the hardware cursor, that may be the approach I need to take anyway in order to boost my programs performance. I am rendering a spectrogram and it is too slow!

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @Yippiyak
                          Is the spectrogram using openGL or just QPainter?

                          Y 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @Yippiyak
                            Is the spectrogram using openGL or just QPainter?

                            Y Offline
                            Y Offline
                            Yippiyak
                            wrote on last edited by
                            #13

                            @mrjj
                            Just qpainter and qcharts atm, which I suspect is my issue, but I also have no real clue how to even begin with OpenGL. Also would you mind upvoting my reputation? I can only post once every 10 min and its getting annoying haha.

                            mrjjM 1 Reply Last reply
                            1
                            • Y Yippiyak

                              @mrjj
                              Just qpainter and qcharts atm, which I suspect is my issue, but I also have no real clue how to even begin with OpenGL. Also would you mind upvoting my reputation? I can only post once every 10 min and its getting annoying haha.

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @Yippiyak said in How to increase refresh rate on mouseMoveEvent?:

                              qcharts

                              well for QLineSeries and QScatterSeries, it seems easy
                              https://doc.qt.io/Qt-5/qtcharts-openglseries-example.html
                              for other im not sure.

                              Y 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                @Yippiyak said in How to increase refresh rate on mouseMoveEvent?:

                                qcharts

                                well for QLineSeries and QScatterSeries, it seems easy
                                https://doc.qt.io/Qt-5/qtcharts-openglseries-example.html
                                for other im not sure.

                                Y Offline
                                Y Offline
                                Yippiyak
                                wrote on last edited by
                                #15

                                @mrjj
                                Yeah im running the acceleration but its still not fast enough. Dumb part is the code works flawlessly in my c# implementation but C++ is brutalizing it. Should be the other way around.

                                mrjjM 1 Reply Last reply
                                0
                                • Y Yippiyak

                                  @mrjj
                                  Yeah im running the acceleration but its still not fast enough. Dumb part is the code works flawlessly in my c# implementation but C++ is brutalizing it. Should be the other way around.

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  @Yippiyak
                                  Thats odd. what graph did you use with c# ?

                                  Y 1 Reply Last reply
                                  0
                                  • mrjjM mrjj

                                    @Yippiyak
                                    Thats odd. what graph did you use with c# ?

                                    Y Offline
                                    Y Offline
                                    Yippiyak
                                    wrote on last edited by
                                    #17

                                    @mrjj
                                    A pretty basic line plot using direct3d hardware acceleration and like 60 other files lol

                                    mrjjM 1 Reply Last reply
                                    0
                                    • Y Yippiyak

                                      @mrjj
                                      A pretty basic line plot using direct3d hardware acceleration and like 60 other files lol

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by mrjj
                                      #18

                                      @Yippiyak
                                      Ok so most likely your plotter is just more specialized than QtChart and hence the speed difference.
                                      You could try some test with direct openGL to see if it is faster

                                      Y 1 Reply Last reply
                                      0
                                      • mrjjM mrjj

                                        @Yippiyak
                                        Ok so most likely your plotter is just more specialized than QtChart and hence the speed difference.
                                        You could try some test with direct openGL to see if it is faster

                                        Y Offline
                                        Y Offline
                                        Yippiyak
                                        wrote on last edited by
                                        #19

                                        @mrjj
                                        Yeah, I think that is the issue, but I am not entirely sure how to get started with converting what I have to OpenGL and what not.

                                        mrjjM 1 Reply Last reply
                                        0
                                        • Y Yippiyak

                                          @mrjj
                                          Yeah, I think that is the issue, but I am not entirely sure how to get started with converting what I have to OpenGL and what not.

                                          mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #20

                                          @Yippiyak
                                          well it really depends on how your layered your plotter
                                          most of the work would to replace the Direct3D calls.
                                          this is a very basic get started example
                                          http://doc.qt.io/qt-5/qtgui-openglwindow-example.html

                                          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