[PyQt] Selecting many rows in a QTableView

David Cortesi davecortesi at gmail.com
Tue Aug 9 15:41:06 BST 2016


A possible solution would be to forego the use of an actual selection in
favor of your own custom coloring of "relevant" fields. It doesn't seem to
me that a 10000 item "selection" is much use anyway, as the first click in
a cell will clear it. Don't you simply want to visually distinguish certain
values?

The key to that would be in the data() method, which is called for the
visible cells for many "roles" other than the DisplayRole. See [1]. For
example, when called for the Qt.BackgroundRole, it could return a Pink
QBrush when the value of a cell meets your criteria and a White one
otherwise. Or, when called for the Qt.FontRole, it could return a QFont
with bold or italic in one case, and normal text in the other.

Date: Mon, 8 Aug 2016 23:26:47 +0100
> From: Thomas Robitaille <thomas.robitaille at gmail.com>
> To: pyqt at riverbankcomputing.com
> Subject: [PyQt] Selecting many rows in a QTableView
>
> class DataTableModel(QtCore.QAbstractTableModel):
>


>     def data(self, index, role):
>         if not index.isValid():
>             return None
>         if role == Qt.DisplayRole:
>             return "({0},{1})".format(index.row(), index.column())
>
>
[1] http://doc.qt.io/qt-5/qt.html#ItemDataRole-enum
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160809/b9ddd9f7/attachment.html>


More information about the PyQt mailing list