简体   繁体   English

QProgressBar PyQt5

[英]QProgressBar PyQt5

I have a QPushButton which when clicked runs a function to plot a graph.我有一个 QPushButton,单击它会运行一个 function 到 plot 的图表。

I want a progressbar below that QPushButton showing busy indicator.我想要一个显示忙碌指示器的 QPushButton 下面的进度条。 I dnt want the percentage or any logic in the bar just the looping type bar we get by setting -我不希望栏中的百分比或任何逻辑只是我们通过设置获得的循环类型栏 -

self.progressbar.setMinimum(0)
self.progressbar.setMaximum(0)

I dnt want this bar to show in the UI initially so i have set-我不希望这个栏最初显示在 UI 中,所以我设置了-

self.progressbar.setVisible(False)

And then this to show the bar:然后这是显示栏:

def functiontoplotgraph(self):
    self.progressbar.setVisible(True)
    ---#code to plot graph
    self.progressbar.hide()

My problem is the bar shows after the data is plotted.我的问题是在绘制数据后显示条形图。 i want it to show when i click the button and hide when plot is shown.我希望它在我单击按钮时显示并在显示 plot 时隐藏。

Import QApplication and call QApplication.processEvents() immediately after self.progressbar.setVisible(True) .导入QApplication并在self.progressbar.setVisible(True)之后立即调用QApplication.processEvents() ) 。

The reason is that many actions are not done immediately as you call them in code (typically showing/hiding/resizing/layouting) but are queued in even queue.原因是许多操作在您在代码中调用它们时并没有立即完成(通常是显示/隐藏/调整大小/布局),而是在偶数队列中排队。 By calling processEvents() you will force to do them right away.通过调用processEvents()您将强制立即执行它们。 So I assume this should help.所以我认为这应该有所帮助。

In some cases you should also try QApplication.sendPostedEvents() before processEvents() .在某些情况下,您还应该在processEvents() QApplication.sendPostedEvents() ) 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM