gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 14:45:26 26 4
gpt4 key购买 nike

我正在尝试使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com