python - 从 PyCharm IDE 启动时如何在 PyQt5 中使用 QOpenGLWidget 而不会卡住应用程序?

标签 python opengl pyqt pycharm pyqt5

我正在尝试使用 PyQt5 创建一个应用程序,但每当我尝试合并 QOpenGLWidget (或派生类)时,我的应用程序就会卡住(Windows 标题栏显示“无响应”)。下面是演示该问题的完整程序。当我将 show_gl_widget 设置为 True 时,启动的应用程序卡住。

import sys

from PyQt5.QtWidgets import QApplication, QMainWindow, QOpenGLWidget, QHBoxLayout, QWidget, QLabel

app = QApplication(sys.argv)
main_window = QMainWindow()
central_widget = QWidget(parent=main_window)
main_window.setCentralWidget(central_widget)
layout = QHBoxLayout()
show_gl_widget = False  # Set show_gl_widget to True to see the problem
if show_gl_widget:  # Window shows, but hangs with "Not responding" this way
    gl_widget = QOpenGLWidget(parent=main_window.centralWidget())
    layout.addWidget(gl_widget)
else:  # Works OK this way
    label = QLabel(parent=main_window.centralWidget(), text='Hey!')
    layout.addWidget(label)
main_window.centralWidget().setLayout(layout)
main_window.show()
sys.exit(app.exec_())

我在使用 64 位 python 3.6.2 的 Windows 10 上遇到此问题。我没有尝试过其他环境。

编辑:当我从命令行运行该程序时,该程序可以正确运行,但当我从 PyCharm IDE 运行时,该程序无法正确运行。为什么从 PyCharm IDE 运行时应用程序会卡住?

最佳答案

一个答案是“将 pycharm 拖到您的另一台显示器上”。

我使用两台显示器和一个扩展桌面。当我观察到此问题时,我正在扩展桌面的右半部分的辅助显示器上使用 PyCharm IDE。如果我从第二个显示器启动应用程序,无论是从 PyCharm、Eclipse 还是命令行,应用程序都会卡住。如果我使用这些方法中的任何一种从左显示器启动,应用程序运行正常。

我怀疑这是 PyQt5/QOpenGLWidget 的错误。 PyCharm 不应该为此负责。

关于python - 从 PyCharm IDE 启动时如何在 PyQt5 中使用 QOpenGLWidget 而不会卡住应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46269663/

相关文章:

python - python3 类型转换是否输入了 input() 值?

python - 如何使用 Python 将数据上传到 Tableau Server

c++ - 编写支持 OpenGL 的 GUI

c++ - 错误的访问代码 1 glDrawElements

python - SQLite 和 tableWidget

Python 以安全的方式关闭文件数组

python - 在 Python 中从 Enum 创建字典时,'float' 对象不可调用

android - 为什么很多移动 GPU 支持 OpenGL ES,而不支持 OpenGL?

python - QlistWidget - 具有多个信号/连接的列表?

python - 我想将文本放入 pyqt QCalendarWidget