3

I upgraded my Qgis to 3.0.1 and I try to upgrade some of the plugins I wrote.

I have a plugin which uses GDAL/rastercalculator from several raster layers to get new informations.

With Qgis2 api it was easy to add a progress dialog to the process :

progress = QProgressDialog("Calcul", "Annuler", 0, 100,self.dockwidget)
calc = QgsRasterCalculator(formula, output_path, 'GTiff', map.extent(), map.width(), map.height(), entries)
calc.processCalculation(progress)

Qgis3 api uses a QgsFeedback instead of a QProgressDialog (see https://qgis.org/api/api_break.html).

Does anyone knows how to use QgsFeedback to create a progress bar ? I couldn't find any example.

Update 2019/03/07 : I found a way to do it :

feedback = QgsFeedback(self.dockwidget)
progress = QProgressDialog("Processing...","Cancel", 0, 100, self.dockwidget)
progress.setWindowModality(Qt.WindowModal)
progress.setMinimumDuration(500)
feedback.progressChanged.connect(progress.setValue)
progress.show()
calc = QgsRasterCalculator( formula, output_path, 'GTiff', slope_map.extent(), slope_map.width(), slope_map.height(), entries)
calc.processCalculation(feedback)

Now it works.

  • Did you try like that: for line1: feedback= QgsFeedback(self.dockwidget) or feedback= QgsRasterBlockFeedback(self.dockwidget) .... for line3: calc.processCalculation(feedback). Not sure that may help. – Kadir Şahbaz Apr 10 '18 at 9:59
  • Great you found it, did you know you can make an answer to your own question? That will help others in the same situation to discover this solution. – Matthias Kuhn Mar 10 at 14:25
  • How ? I did not find a way to answer, that's why I edited the question. – Jacques Beilin Mar 10 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.