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?

How to increase refresh rate on mouseMoveEvent?

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 4 Posters 6.1k Views
  • 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.
  • V Violet Giraffe
    10 Jul 2018, 19:27

    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 10 Jul 2018, 20:20 last edited by Yippiyak 7 Oct 2018, 20:27
    #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?

    M 1 Reply Last reply 10 Jul 2018, 20:29
    0
    • Y Yippiyak
      10 Jul 2018, 20:20

      @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?

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 10 Jul 2018, 20:29 last edited by mrjj 7 Oct 2018, 20:34
      #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 10 Jul 2018, 20:38
      1
      • M mrjj
        10 Jul 2018, 20:29

        @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 10 Jul 2018, 20:38 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.

        M 1 Reply Last reply 10 Jul 2018, 20:50
        0
        • Y Yippiyak
          10 Jul 2018, 20:38

          @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.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 10 Jul 2018, 20:50 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 10 Jul 2018, 21:03 last edited by Yippiyak 7 Oct 2018, 21:03
            #9

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

            M 1 Reply Last reply 10 Jul 2018, 21:07
            1
            • Y Yippiyak
              10 Jul 2018, 21:03

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

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 10 Jul 2018, 21:07 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 10 Jul 2018, 21:16
              1
              • M mrjj
                10 Jul 2018, 21:07

                @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 10 Jul 2018, 21:16 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!

                M 1 Reply Last reply 10 Jul 2018, 21:18
                0
                • Y Yippiyak
                  10 Jul 2018, 21:16

                  @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!

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 10 Jul 2018, 21:18 last edited by
                  #12

                  @Yippiyak
                  Is the spectrogram using openGL or just QPainter?

                  Y 1 Reply Last reply 10 Jul 2018, 21:48
                  0
                  • M mrjj
                    10 Jul 2018, 21:18

                    @Yippiyak
                    Is the spectrogram using openGL or just QPainter?

                    Y Offline
                    Y Offline
                    Yippiyak
                    wrote on 10 Jul 2018, 21:48 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.

                    M 1 Reply Last reply 10 Jul 2018, 21:54
                    1
                    • Y Yippiyak
                      10 Jul 2018, 21:48

                      @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.

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 10 Jul 2018, 21:54 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 10 Jul 2018, 21:57
                      0
                      • M mrjj
                        10 Jul 2018, 21:54

                        @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 10 Jul 2018, 21:57 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.

                        M 1 Reply Last reply 10 Jul 2018, 22:01
                        0
                        • Y Yippiyak
                          10 Jul 2018, 21:57

                          @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.

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 10 Jul 2018, 22:01 last edited by
                          #16

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

                          Y 1 Reply Last reply 10 Jul 2018, 22:24
                          0
                          • M mrjj
                            10 Jul 2018, 22:01

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

                            Y Offline
                            Y Offline
                            Yippiyak
                            wrote on 10 Jul 2018, 22:24 last edited by
                            #17

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

                            M 1 Reply Last reply 10 Jul 2018, 22:37
                            0
                            • Y Yippiyak
                              10 Jul 2018, 22:24

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

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 10 Jul 2018, 22:37 last edited by mrjj 7 Oct 2018, 22:38
                              #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 10 Jul 2018, 22:40
                              0
                              • M mrjj
                                10 Jul 2018, 22:37

                                @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 10 Jul 2018, 22:40 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.

                                M 1 Reply Last reply 10 Jul 2018, 23:07
                                0
                                • Y Yippiyak
                                  10 Jul 2018, 22:40

                                  @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.

                                  M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 10 Jul 2018, 23:07 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
                                  • 6 Offline
                                    6 Offline
                                    6ziv
                                    wrote on 11 Jul 2018, 04:19 last edited by
                                    #21

                                    Well in my opinion maybe you can try not refreshing immediately. Just record the position in a fifo and return. You can get yourself another thread which looks through the fifo and draws, so the handler may return faster, and missing fewer. Well...in fact I am not very sure of this....

                                    1 Reply Last reply
                                    0

                                    14/21

                                    10 Jul 2018, 21:54

                                    • Login

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