Skip to content

Instantly share code, notes, and snippets.

@onlyjus
Created October 17, 2014 18:01
Show Gist options
  • Select an option

  • Save onlyjus/d7f99fb16e9e904e3ba0 to your computer and use it in GitHub Desktop.

Select an option

Save onlyjus/d7f99fb16e9e904e3ba0 to your computer and use it in GitHub Desktop.
Custom progress bar with cancel button and label overlay.
class ProgressBar(QtGui.QWidget):
"""
Custom progress bar hack that allows text over a 'busy' progress bar.
Also adds a cancel button.
"""
cancel = QtCore.Signal(object)
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
# Progress Bar
self.bar = QtGui.QProgressBar()
# Label over progress bar
self.label = QtGui.QLabel()
# cancel button
self.cancelButton = QtGui.QToolButton()
self.cancelButton.setAutoRaise(True)
self.cancelButton.pressed.connect(lambda:self.cancel.emit(True))
grid = QtGui.QGridLayout()
grid.setSpacing(0)
grid.setContentsMargins(0, 0, 0, 0)
grid.addWidget(self.bar, 0, 0)
grid.addWidget(self.label, 0, 0)
grid.addWidget(self.cancelButton, 0, 1)
self.setLayout(grid)
def setRange(self, min_, max_):
self.bar.setRange(min_, max_)
def setMaximum(self, value):
self.bar.setMaximum = value
def setMinimum(self, value):
self.bar.setMinimum = value
def setValue(self, value):
self.bar.setValue(value)
def setFormat(self, text):
if self.bar.maximum() == self.bar.minimum() == 0:
self.label.setText(text)
self.label.show()
else:
self.label.hide()
self.bar.setFormat(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment