[PyQt] need help, progressbar in TableWdiget can not fill full width of column

Qi Wang wangqi0316 at gmail.com
Thu Mar 7 03:18:19 GMT 2013


hi,all,
I'm not sure it is appropriated to post this general question here, it not,
please give me reminder.

I want to add progressbar into table widget with QStyleItemDelegate, it
show progressbar on specific column, but the the progressbar does not fill
full width of column. I also attached the screenshot to this mail.


following is my code snippet.

class CProgressBarDeletgate(QtGui.QStyledItemDelegate):

    def paint(self, painter, optionViewItem, modelIndex):
        progress_value = int(str(str(modelIndex.data().toPyObject())))
        progressBarOption = QtGui.QStyleOptionProgressBar()
        progressBarOption.rect = optionViewItem.rect

        progressBarOption.minimum = 0
        progressBarOption.maximum = 100
        progressBarOption.progress = progress_value
        progressBarOption.state = QtGui.QStyle.State_Enabled
        progressBarOption.textVisible = True
        QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_ProgressBar,
progressBarOption, painter)

    def __init__(self, parent=None):
        super(CProgressBarDeletgate, self).__init__(parent)


following is tablewidget initialization code:
        self._ui.tableWidget.setColumnCount(2)

self._ui.tableWidget.setHorizontalHeaderLabels(['FileName','Progress'])
        self._ui.tableWidget.setItemDelegateForColumn(1,
CProgressBarDeletgate())
        #self._ui.tableWidget.verticalHeader().setDefaultSectionSize()
        default_height =
self._ui.tableWidget.verticalHeader().defaultSectionSize()

self._ui.tableWidget.verticalHeader().setDefaultSectionSize(default_height
- 10)


Thank you so much~!

-- 
------------
best regards

Wang Qi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130307/e5ed3916/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: progessbar_in_tablewidget.png
Type: image/png
Size: 5042 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130307/e5ed3916/attachment-0001.png>


More information about the PyQt mailing list