[PySide] custom painted content in delegate disappears when cell is selected

Frank Rueter | OHUfx frank at ohufx.com
Sat May 5 06:04:58 CEST 2018


Interestingly this does not happen when drawing a pixmap.

On 5/05/18 3:27 PM, Frank Rueter | OHUfx wrote:
> Hi all,
>
> I am drawing some rectangles into my cell via a delegate's paint event 
> like so:
>
>
> When I click one in the cells, the rectangles disappear, sometimes 
> with a lag. Sometimes they reappear when I click another cell.
>
>
> The text drawn by the default paint event behaves fine, so I am 
> clearly missing something (probably obvious).
> Below is my test code.
> Any ideas? I'm sure I have a slap-on-the-forehead moment coming up...
>
> Cheers,
> frank
>
> from PySide2 import QtWidgets
> from PySide2 import QtCore
>
>
> class VersionTableModel(QtCore.QAbstractTableModel):
>     def __init__(self, parent=None):
>         super(VersionTableModel, self).__init__(parent)
>         self.customData = [range(6)] * 4
>
>     def rowCount(self, index=None):
>         return 4
>
>     def columnCount(self, index=None):
>         return 6
>
>     def data(self, index, role):
>         if role == QtCore.Qt.DisplayRole:
>             try:
>                 return 
> "{}".format(self.customData[index.row()][index.column()] )
>             except TypeError:
>                 return None
>
>
> class VersionItemDelegate(QtWidgets.QStyledItemDelegate):
>
>     def paint(self, painter, option, index):
>         super(self.__class__, self).paint(painter, option, index)
>         # paint custom icon
>         mv_rect1 = QtCore.QRect(0,0,18,10)
>         mv_rect1.moveTopRight(option.rect.bottomLeft() + 
> QtCore.QPoint(-18, -22))
>         mv_rect2 = mv_rect1.translated(3, 3)
>         mv_rect3 = mv_rect2.translated(3, 3)
>         painter.setPen(QtCore.Qt.white)
>         painter.setBrush(QtCore.Qt.red)
>         for r in (mv_rect1, mv_rect2, mv_rect3):
>             painter.drawRect(r)
>
>
> if __name__ == '__main__':
>     import sys
>     app = QtWidgets.QApplication([])
>     tableView = QtWidgets.QTableView()
>     tableView.setModel(VersionTableModel())
>     tableView.setItemDelegate(VersionItemDelegate())
>     tableView.show()
>     sys.exit(app.exec_())
>
> -- 
>
> ohufxLogo 50x50 <http://www.ohufx.com> 	
> 	*vfx compositing <http://ohufx.com/compositing.html> | *workflow 
> customisation and consulting <http://ohufx.com/customising.html>* *
> 		*<http://ohufx.com/compositing.html>*
> <http://www.nukepedia.com/nubridge> 	
> 	
>
> Your gateway to over 1,000 free tools... right inside of Nuke 
> <http://www.nukepedia.com/nubridge>
>
>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20180505/6021620c/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: idbogdmibdhpjiel.png
Type: image/png
Size: 21472 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20180505/6021620c/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mihocedglmdjhbmg.png
Type: image/png
Size: 21255 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20180505/6021620c/attachment-0001.png>


More information about the PySide mailing list