■表示する文字を変更する
QProgressBarに表示する文字を変更するには、sefFormatを使います。
以下の文字はそれぞれ置換されるようです。
- %p…進捗率
- %v…完了した数
- %m…全体の数
■表示スタイルの変更
QProgressBarの見た目を変更するには、setStyleSheetを利用します。
外枠の部分を変更する場合は、QProgressBarを、内側のバーを変更する場合はQProgressBar::chunkを設定するようです。
指定できるスタイルの種類は調べきれていません。
参考:Customizing QProgressBar
■ビジー状態の表示
ビジー状態などで、進捗率は表示できないけれどバーは動かしたい場合は、QProgressBarのMaximumとMinimumを共に設定すれば良いようです。
Maquee styleと言うみたいですね。
参考:http://qt-project.org/forums/viewthread/2350
試しに動かしてみました。
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui
# Progress bar styles
PENDING_PASS_STYLE = """
QProgressBar {
text-align: center;
height: 15px;
}
QProgressBar::chunk {
width: 10px;
}
"""
FIRST_PASS_STYLE = """
QProgressBar {
text-align: center;
height: 15px;
}
QProgressBar::chunk {
background-color: orange;
width: 10px;
margin: 1px;
}
"""
SECOND_PASS_STYLE = """
QProgressBar {
text-align: center;
height: 15px;
}
QProgressBar::chunk {
background-color: lime;
width: 10px;
margin: 1px;
}
"""
# dummy data for test
dummydata = [
{
"path": "Title A",
"progress": 79,
"pass": 2
}, {
"path": "Movie B",
"progress": 18,
"pass": 2
}, {
"path": "Dummy",
"progress": 35,
"pass": 0
}, {
"path": "HogeHoge",
"progress": 15,
"pass": 1
}
]
class ProcessTreeView(QtGui.QTreeView):
def __init__(self):
super(ProcessTreeView, self).__init__()
self._datamodel = QtGui.QStandardItemModel(0, 2)
self._datamodel.setHeaderData(0, QtCore.Qt.Horizontal, 'Title')
self._datamodel.setHeaderData(1, QtCore.Qt.Horizontal, 'Process')
self.setModel(self._datamodel)
index = 0
for element in dummydata:
self._add_item(element, index)
index = index + 1
self.show()
def _add_item(self, process, n):
titleitem = QtGui.QStandardItem(process.get('path', u''))
self._datamodel.setItem(n, 0, titleitem)
pbar = QtGui.QProgressBar(self)
pbar.setValue(process.get('progress', 0))
if process.get('pass', 0) == 1:
pbar.setStyleSheet(FIRST_PASS_STYLE)
pbar.setFormat('First Pass:%p%')
pbar.setRange(0, 100)
elif process.get('pass', 0) == 2:
pbar.setStyleSheet(SECOND_PASS_STYLE)
pbar.setFormat('Second Pass:%p%')
pbar.setRange(0, 100)
else:
pbar.setStyleSheet(PENDING_PASS_STYLE)
pbar.setFormat('')
# maquee style
pbar.setRange(0, 0)
index = self._datamodel.index(n, 1, QtCore.QModelIndex())
self.setIndexWidget(index, pbar)
def _delete_item(self):
self._datamodel.removeRow(0)
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.treeview = ProcessTreeView()
hbox = QtGui.QHBoxLayout()
hbox.addWidget(self.treeview)
self.setLayout(hbox)
self.setGeometry(300, 300, 400, 200)
self.setWindowTitle('Tree view test')
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
実行結果。
上から3番目がMaquee style progress barです。

0 件のコメント:
コメントを投稿