以下简单代码仅输出None
两次,原因可能是什么?我可以看到黑色窗口,但由于无法访问GL功能,因此无法绘制任何内容。
from PyQt5.QtGui import QOpenGLWindow
from PyQt5.QtWidgets import QApplication
import sys
class MainWindow(QOpenGLWindow):
def paintGL(self):
print self.context().versionFunctions()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
答案 0 :(得分:0)
我在这里找到了一个很好的例子:https://github.com/pbouda/stuff/blob/master/opengl/pyqt/chocolux.py
问题在于错误的GL配置文件:尽管我的视频卡有4.4,但PyQt仅支持2.0和2.1。这是可悲的,说实话......
1.0 failed: No module named _QOpenGLFunctions_1_0
1.1 failed: No module named _QOpenGLFunctions_1_1
1.2 failed: No module named _QOpenGLFunctions_1_2
1.3 failed: No module named _QOpenGLFunctions_1_3
1.4 failed: No module named _QOpenGLFunctions_1_4
1.5 failed: No module named _QOpenGLFunctions_1_5
2.0 is ok
2.1 is ok
3.0 failed: No module named _QOpenGLFunctions_3_0
3.1 failed: No module named _QOpenGLFunctions_3_1
我用以下代码得到了这个:
def paintGL(self):
for i in xrange(0, 5):
for j in xrange(0, 1000):
version = QtGui.QOpenGLVersionProfile()
version.setVersion(i, j)
try:
if self.context().versionFunctions(version) is not None: print '{}.{} is ok'.format(i, j)
except Exception as e:
print '{}.{} failed: {}'.format(i, j, e)