如何在PyQt5中使用QOpenGLWidget而不冻结从PyCharm IDE启动的应用程序?

2024-09-25 10:27:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用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位Python3.6.2的Windows10上遇到了这个问题。我没有尝试过其他环境。在

编辑:当我从命令行运行该程序时,它会正确运行,但从PyCharm IDE运行时则不会。为什么从PyCharm IDE运行时应用程序会冻结?在


Tags: import程序true应用程序mainshowsyswidget
1条回答
网友
1楼 · 发布于 2024-09-25 10:27:27

一个答案是“把pycharm拖到另一个显示器上”。在

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

我怀疑这是PyQt5/QOpenGLWidget的一个bug。PyCharm在这里不是罪魁祸首。在

相关问题 更多 >