[PyQt] display a widget in a QTableView

Wim Verhavert wim.verhavert at gmail.com
Fri Oct 17 10:00:31 BST 2008


This seems to work. Thanks! It helped me a lot to think about the
problem. One thing though: the actual value is only displayed when I
increase the width of my cell enough. I included 2 screenshots as
illustration. Can I control this with some options? I do not want to
increase the size this much if possible.

On Thu, Oct 16, 2008 at 7:06 PM, Kovid Goyal <kovid at kovidgoyal.net> wrote:
> class ProgressBarDelegate(QAbstractItemDelegate):
>
>    def sizeHint(self, option, index):
>        return QSize(120, 30)
>
>    def paint(self, painter, option, index):
>        opts = QStyleOptionProgressBarV2()
>        opts.rect = option.rect
>        opts.minimum = 1
>        opts.maximum = 100
>        opts.textVisible = True
>        percent, ok = index.model().data(index, Qt.DisplayRole).toInt()
>        if not ok:
>            percent = 0
>        opts.progress = percent
>        opts.text = QString(_('Unavailable') if percent == 0 else
> '%d%%'%percent)
>        QApplication.style().drawControl(QStyle.CE_ProgressBar, opts, painter)
>
> On Thursday 16 October 2008 09:50:54 Wim Verhavert wrote:
>> Dear all,
>>
>> I want to do something in PyQT I have seen many times in other
>> applications: A QTableView where the last column contains a QProgressbar.
>> Basically I want to implement some kind of cue where each item is processed
>> which can take a while. To give some visual feedback I want to display
>> a progressbar in the last column. This would allow sorting on progress
>> and such.
>> I have the book 'Rapid GUI Programming with Python and Qt' by Mark
>> Summerfield at hand which contains a section about custom delegates. I
>> have done similar things in the past, but somehow I'm not able to
>> translate this into the thing I want to do. Is there somebody out
>> there that could give me a head start?
>>
>> I think it will need to create a custom delegate and override the
>> paint method. But how? How do I paint a progressbar? Do I have to do
>> this from scratch, i.e. filling a part of the cell with a color, or
>> can I use a QProgressbar? Any suggestions are welcome.
>>
>> Cheers!
>>
>> Wim
>> _______________________________________________
>> PyQt mailing list    PyQt at riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
>> !DSPAM:3,48f771b131535171880063!
>
> --
> _____________________________________
>
> Kovid Goyal  MC 452-48
> California Institute of Technology
> 1200 E California Blvd
> Pasadena, CA 91125
>
> cell  : +01 626 390 8699
> office: +01 626 395 6595 (449 Lauritsen)
> email : kovid at theory.caltech.edu
> web   : http://www.kovidgoyal.net
> _____________________________________
>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: no-value-indication.png
Type: image/png
Size: 27670 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20081017/19c95a7c/no-value-indication-0001.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: minimal-size-to-display-all-values.png
Type: image/png
Size: 29673 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20081017/19c95a7c/minimal-size-to-display-all-values-0001.png


More information about the PyQt mailing list