-4

I'm working on a program and I want to connect a QProgressBar with a function. While the function is in progress, the QProgressBar should count until the function is done. Then the QProgressBar should be done too.

Wes
  • 4,781
  • 7
  • 44
  • 53
s.jor.ibra
  • 307
  • 1
  • 5
  • 16
  • 4
    You should maybe accept more answers for questions you've asked in the past. You've only accepted answers on 9% of the questions you've asked. This will not inspire others to help you. – Wes Feb 16 '12 at 15:20
  • 2
    Read the QProgressBar documentation, it's quite clear on how to use it. https://developer.qt.nokia.com/doc/qt-4.8/qprogressbar.html#details – cmannett85 Feb 16 '12 at 15:25

1 Answers1

1

This sample will give you a simple idea of seeing the progress. By no way this is efficient or elegant. Its a just a working solution i rigged up.

#!/usr/bin/python

import os, sys

from time import sleep

from PyQt4.QtCore import *
from PyQt4.QtGui import *

app = QApplication( sys.argv )

def copyFile() :
    cpBtn.setDisabled( True )
    for i in range( 0, 100 ) :
        # File Copy Code
        # sleep( 0.1 ) is instead of the file copy code
        sleep( 0.1 )
        pb.setValue( i + 1 )
        qApp.processEvents()

    cpBtn.setEnabled( True )
    pb.reset()

fcpDlg = QDialog()

cpBtn = QPushButton( fcpDlg )
cpBtn.setText( "&Copy" )
cpBtn.clicked.connect( copyFile )
cpBtn.setFixedWidth( 72 )

pb = QProgressBar()
pb.setMinimumWidth( 300 )
pb.setRange( 0, 100 )

lyt = QVBoxLayout( fcpDlg )
lyt.addWidget( pb )
lyt.addWidget( cpBtn )

fcpDlg.setLayout( lyt )

fcpDlg.show()

sys.exit( app.exec_() )
Marcus
  • 1,685
  • 1
  • 18
  • 33