Book Image

QGIS Python Programming Cookbook

Book Image

QGIS Python Programming Cookbook

Overview of this book

Table of Contents (16 chapters)
QGIS Python Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Displaying a progress bar


A progress bar is a dynamic dialog that displays the percentage complete bar for a running process that the user must wait for before continuing. A progress bar is more advanced than a simple dialog because it needs to be updated continuously. In this recipe, we'll create a simple progress dialog based on a timer.

Getting ready

No groundwork is required for this recipe.

How to do it...

The steps for this recipe include creating a custom class based on the QProgressBar, initializing the dialog and setting its size and title, creating a timer, connecting the progress bar to the timer, starting the time, and displaying the progress. To do this, we need to perform the following steps:

  1. First, we must import both the GUI and QGIS core libraries:

    from PyQt4.QtGui import *
    from PyQt4.QtCore import *
    
  2. Next, we create a custom class for our progress bar, including a method to increase the value of the progress bar:

    class Bar(QProgressBar):
      value = 0
      def increaseValue(self):
    ...