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
[email protected]
http://lists.qt-project.org/mailman/listinfo/pyside

Reply via email to