SHOW:
|
|
- or go back to the newest paste.
| 1 | from PyQt4 import QtCore, QtGui | |
| 2 | ||
| 3 | ||
| 4 | class StatusWidgetBar(QtGui.QComboBox): | |
| 5 | def __init__(self, parent=None): | |
| 6 | super(StatusWidgetBar, self).__init__(parent) | |
| 7 | - | |
| 7 | + | |
| 8 | self.addItems(['waiting', 'in progress', 'finished']) | |
| 9 | ||
| 10 | - | painter.setRenderHint(QtGui.QPainter.Antialiasing) |
| 10 | + | |
| 11 | - | parent = self.parentWidget() |
| 11 | + | super(StatusWidgetBar, self).paintEvent(event) |
| 12 | - | progress = self.currentIndex() * .5 |
| 12 | + | |
| 13 | progressBarStyleOption = QtGui.QStyleOptionProgressBar() | |
| 14 | - | painter.setPen(QtGui.QColor(0,0,0,0)) |
| 14 | + | progressBarStyleOption.rect = QtCore.QRect(0, 0, (self.width()), self.height()) |
| 15 | - | if progress <= .5: |
| 15 | + | progressBarStyleOption.minimum = 0 |
| 16 | - | painter.setBrush(QtGui.QColor(255, 140, 30)) |
| 16 | + | progressBarStyleOption.maximum = self.count() |
| 17 | - | else: |
| 17 | + | progressBarStyleOption.textAlignment = QtCore.Qt.AlignCenter |
| 18 | - | painter.setBrush(QtGui.QColor('darkGreen'))
|
| 18 | + | progressBarStyleOption.progress = self.currentIndex() |
| 19 | progressBarStyleOption.textVisible = True | |
| 20 | - | barRect = QtCore.QRect(0, 0, (self.width()) * progress, self.height()) |
| 20 | + | painter.setOpacity(0.5) |
| 21 | - | painter.drawRect(barRect) |
| 21 | + | QtGui.qApp.style().drawControl(QtGui.QStyle.CE_ProgressBar, progressBarStyleOption, painter) |
| 22 | ||
| 23 | ||
| 24 | app = QtGui.QApplication([]) | |
| 25 | w = StatusWidgetBar() | |
| 26 | w.show() | |
| 27 | app.exec_() |