[PyQt] Hidden rows with span on QTableView

Maurizio Berti maurizio.berti at gmail.com
Sat Mar 24 20:53:13 GMT 2018


I just found a strange behavior in QTableView, which seems to be present in
both PyQt 4.12 and 5.7.1 at least.
When an item has rowspan set and that row is hidden via setRowHidden, a
"ghost" text of the hidden item is still visible between the remaining
visible rows.
I suppose it can be a Qt bug, but I'd prefer to be sure before reporting it.

I'm attaching screenshots (I hope that's not a problem, they're very small)
and this is a sample code to test it with:

class Table(QtWidgets.QWidget):
    def __init__(self):
        QtWidgets.QWidget.__init__(self)
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)
        self.table = QtWidgets.QTableView()
        layout.addWidget(self.table)
        self.model = QtGui.QStandardItemModel()
        self.table.setModel(self.model)
        self.check = QtWidgets.QCheckBox('show')
        layout.addWidget(self.check)
        self.check.setChecked(True)
        self.check.toggled.connect(self.toggle)
        for row in range(10):
            if row & 1:
                item = QtGui.QStandardItem('will hide')
                self.model.appendRow(item)
                if row != 1:
                    self.table.setSpan(row, 0, 1, 2)
            else:
                item = QtGui.QStandardItem('keep visible')
                item2 = QtGui.QStandardItem('item')
                self.model.appendRow([item, item2])

    def toggle(self, state):
        if state:
            for row in range(self.model.rowCount()):
                self.table.setRowHidden(row, False)
        else:
            for row in range(self.model.rowCount()):
                if row & 1:
                    self.table.setRowHidden(row, True)


Every even row will be shown/hidden when toggling the checkbox, the only
difference is that the second row doesn't has a span set, and the issue
doesn't happen.

Can anyone confirm this, please?

Thanks,
MaurizioB

-- 
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180324/c5b8a0b4/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: table1.jpg
Type: image/jpeg
Size: 10101 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180324/c5b8a0b4/attachment-0002.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: table2.jpg
Type: image/jpeg
Size: 9861 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180324/c5b8a0b4/attachment-0003.jpg>


More information about the PyQt mailing list