Is there a way to display pictures real time in Qt?
-
I'm trying to use QTimer to call QLabel's
setPixmap()
every 5ms to update it in the UI, but the slot function of QTimer is not called every 5ms, and it takes much longer. Similarly, I tested the time interval between twopaintEvent()
calls of QLabel and found it to be about 20ms, which makes it impossible for me to update the UI in real time. But the call ofpaintEvent()
only cost less than 0.1 ms. And I have moved the image rendering task to a subthread, and there are no other time-consuming operations in the slot function of the QTimer, only the call tosetPixmap()
. I wonder if there is any ohter way to makepaintEvent()
called more frequently, or should I use another way to display the pictures in real time? -
@lrq1009962019 said in Is there a way to display pictures real time in Qt?:
every 5ms to update it in the UI
You want to update the picture 200 times per second? Why? Most displays refresh at 60Hz, some go up to 120Hz.
-
I guess that
setPixmap()
internally callsupdate()
.update()
will collect several calls before actually issuing a paint event. If you want to trigger the paint event immediately you need to callrepaint()
. However, doing this too often will result in a sluggish UI.Nevertheless, @jsulm is right: 60Hz for a display means that only roughly every 16ms the screen is redrawn. You cannot physically display a new image every 5ms. And even if you could, humans are not able to perceive this. The best you can do is to drop the image you are not able to display. You would need a 240Hz display to show a new image every 5ms. These are gaming monitors (a lot of them with false advertising, i.e. 240Hz refresh rate of the backlight). Qt is not made for such high through put (though it might work). Instead you should be looking at game development using Vulkan, Metal or DirectX (depending on your OS) to achieve fast graphical performance, if this is really what you want.