I'm building a QGIS
plugin and I want to improve the user interface. I'm able to use processing
tools like buffer
, but with heavy layers I want to display a progress bar, users can easily see the treatment progression.
In documentation, there is some words about it but when I run simples examples, QGIS systematicaly not responding and there isn't any progress bar. Note that this treatment works perfectly without this progress bar issue.
Here is my code :
import time
from qgis.PyQt.QtWidgets import QProgressBar
from qgis.PyQt.QtCore import *
# Progress bar
progressMessageBar = iface.messageBar().createMessage("Work in progress...")
progress = QProgressBar()
progress.setAlignment(Qt.AlignLeft|Qt.AlignVCenter)
progressMessageBar.layout().addWidget(progress)
iface.messageBar().pushWidget(progressMessageBar, Qgis.Info)
# Layer
vlayer = qgis.utils.iface.activeLayer()
count = vlayer.featureCount()
features = vlayer.getFeatures()
# Progression loop
for i, feature in enumerate(features):
percent = i / float(count) * 100
# My treatment
processing.runAndLoadResults('native:buffer', {"INPUT": vlayer, "DISTANCE": 20, "OUTPUT": 'memory:buffer'})
# Progression status
iface.statusBarIface().showMessage("Processed {} %".format(int(percent)))
progress.setValue(percent)
iface.statusBarIface().clearMessage()
Am I missing something ? Maybe something is wrong in my loop. I'm working with QGIS 3.10.1.
QgsMessageBar()
)time.sleep(1)
like in the doc example, just to check.