Python QApplication.SetOverrideCursors对该函数没有影响,为什么?
我正在使用PyQt5构建一个相对简单的UI。应用程序中有几个点运行的进程需要一些时间,因此我使用QApplication.setOverrideCursor来指示进程正在运行 这是通过此装饰器完成的(摘自): 这适用于UI类中的大多数方法,但以下方法除外:Python QApplication.SetOverrideCursors对该函数没有影响,为什么?,python,cursor,pyqt,pyqt5,Python,Cursor,Pyqt,Pyqt5,我正在使用PyQt5构建一个相对简单的UI。应用程序中有几个点运行的进程需要一些时间,因此我使用QApplication.setOverrideCursor来指示进程正在运行 这是通过此装饰器完成的(摘自): 这适用于UI类中的大多数方法,但以下方法除外: @waiting_effects def load_data_folder(self): folder = QtWidgets.QFileDialog.getExistingDirectory(self)
@waiting_effects
def load_data_folder(self):
folder = QtWidgets.QFileDialog.getExistingDirectory(self)
if folder:
self.clear_plot(name="All")
self.vr_headers = []
self.ls_headers = []
self.df = pvi.import_folder(folder)
if self.df['voltage recording'] is not None:
self.vr_headers = self.df['voltage recording'].columns[1:].tolist()
self.sweeps = self.df['voltage recording'].index.levels[0]
if self.df['linescan'] is not None:
self.ls_headers = self.df['linescan'].columns[1::2].tolist()
if self.df['voltage recording'] is None:
self.sweeps = self.df['linescan'].index.levels[0]
self.ratio_dropdown1.clear()
self.ratio_dropdown2.clear()
for profile in self.ls_headers:
self.ratio_dropdown1.addItem(profile)
self.ratio_dropdown2.addItem(profile)
self.tabWidget.setTabEnabled(2, True)
elif self.tabWidget.isTabEnabled(2):
self.tabWidget.setTabEnabled(2, False)
self.update_treeWidget()
在本例中,@waiting_effects装饰器不会对光标产生任何更改
我没有使用decorator,而是尝试使用QApplication.setOverrideCursors在QFileDialog之后包装代码块,但这不起作用。即:
def load_data_folder(self):
folder = QtWidgets.QFileDialog.getExistingDirectory(self)
QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
if folder:
self.clear_plot(name="All")
self.vr_headers = []
self.ls_headers = []
self.df = pvi.import_folder(folder)
if self.df['voltage recording'] is not None:
self.vr_headers = self.df['voltage recording'].columns[1:].tolist()
self.sweeps = self.df['voltage recording'].index.levels[0]
if self.df['linescan'] is not None:
self.ls_headers = self.df['linescan'].columns[1::2].tolist()
if self.df['voltage recording'] is None:
self.sweeps = self.df['linescan'].index.levels[0]
self.ratio_dropdown1.clear()
self.ratio_dropdown2.clear()
for profile in self.ls_headers:
self.ratio_dropdown1.addItem(profile)
self.ratio_dropdown2.addItem(profile)
self.tabWidget.setTabEnabled(2, True)
elif self.tabWidget.isTabEnabled(2):
self.tabWidget.setTabEnabled(2, False)
self.update_treeWidget()
QtWidgets.QApplication.restoreOverrideCursor()
此函数的慢部分是行:
self.df = pvi.import_folder(folder)
这个import_文件夹是我编写的另一个模块中的一个函数,用于加载采集软件生成的数据文件夹。我尝试过用QApplication.setOverrideCursors包装这一行,但同样没有产生任何效果
对这里可能发生的事情有什么想法/建议吗
感谢它看起来像是在主GUI线程中运行的加载数据文件夹函数,因此它将阻止任何进一步的GUI更新,直到完成为止
尝试将
QtWidgets.qApp.processEvents()
放在设置光标的行之后,这应该允许在函数启动之前更新光标。我无法测试代码,但尝试将QtWidgets.qApp.processEvents()
放在设置光标的行之后。是的,这样做了。谢谢如果您不介意解释的话,请随意把它放在一个答案中,我也会更正-这行代码修复了什么问题?
self.df = pvi.import_folder(folder)