How to increase refresh rate on mouseMoveEvent?
-
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!@Yippiyak
Are you certain that the lag is related to mouse events and not to drawing the crosshair, for example? -
@Yippiyak
Are you certain that the lag is related to mouse events and not to drawing the crosshair, for example?@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.
-
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(); }
-
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(); }
@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? -
@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?@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. -
@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. -
@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.
-
@mrjj
No, its threaded and theoretically happens independently. Its just not tracking fast enough.@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-workIm 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. -
@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-workIm 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. -
@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! -
@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.@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. -
@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. -
@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. -
@mrjj
A pretty basic line plot using direct3d hardware acceleration and like 60 other files lol -
@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 -
@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.@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