同步图像显示与屏幕刷新率

Syncing image display with screen refresh rate

程序的作用:使用PyQt4显示图像(简单的jpg/png文件)。

objective: 使屏幕上的图像 displayed/drawn 与屏幕的刷新率同步。

我想要实现的伪代码示例:

pixmap = set_openGL_pixmap(myPixmap) 

draw_openGL_pixmap(pixmap) 

doSomthingElse()

理想情况下,draw_openGL_pixmap(pixmap) 函数应该只在屏幕刷新并显示图像后 return。比 doSomthingElse() 会在真正绘制图像后立即执行。

到目前为止我尝试了什么

总结: 我如何制作 PyQt draw the image on the screen (in a widget) at the exact moment i issue the command, in sync with the screen refresh rate, regardless of PyQt's 事件循环。

感谢 Trialarion 对我的问题的评论,我找到了解决方案 here

对于任何感兴趣的人,这里是 python 显示与屏幕刷新率同步的图像的代码:

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtOpenGL import *

app = QApplication(sys.argv)

# Use a QGLFormat with the swap interval set to 1
qgl_format = QGLFormat()
qgl_format.setSwapInterval(1)

# Construct a QGLWidget using the above format
qgl_widget = QGLWidget(qgl_format)

# Set up a timer to call updateGL() every 0 ms
update_gl_timer = QTimer()
update_gl_timer.setInterval(0)
update_gl_timer.start()
update_gl_timer.timeout.connect(qgl_widget.updateGL)

# Set up a graphics view and a scene
grview = QGraphicsView()
grview.setViewport(qgl_widget)
scene = QGraphicsScene()
scene.addPixmap(QPixmap('pic.png'))
grview.setScene(scene)

grview.show()

sys.exit(app.exec_())