【问题标题】:PySide2: QOpenGLContext' object has no attribute 'functions'PySide2:QOpenGLContext'对象没有属性'functions'
【发布时间】:2018-11-03 11:20:43
【问题描述】:

我正在尝试将新的 QOpenGLWidget 与 PySide2 一起使用,但一开始就出现此错误。

PySide2: QOpenGLContext' object has no attribute 'functions'

我从 c++ 转换为文档中最简单的示例: https://doc.qt.io/qtforpython/PySide2/QtWidgets/QOpenGLWidget.html

def initializeGL(self):
    ctx =  QOpenGLContext.currentContext()
    gl = ctx.functions()
    gl.glClearColor(1.0, 1.0, 1.0, 1.0)

A 找不到任何使用 QOpenGLWidget 的 pyside2 示例,但每个示例都使用 QGLWidget,即使它只是为了向后兼容而保留,并且应该使用新的 QOpenGLWidget。据我所知...

有人可以向我展示一个在 python 中使用 QOpenGLWidget 和 pyside2 的良好且最小的工作示例吗?还是我应该使用旧的 QGLWidget?

PySide.version 返回:“5.6.0~a1”(可能是 Qt 版本) python版本:2.7.15

【问题讨论】:

    标签: python python-2.7 pyside2


    【解决方案1】:

    查看官方存储库中的OpenGL examples 之一,您似乎需要先获取当前上下文。

    QOpenGLContext.currentContext().functions()
    

    另一个问题可能是版本,因为 5.6 已经很老了。可以用最新的 5.12.0 版本试试吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-01
      • 2021-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多