I am trying to display QTableView rows with different colors thanks to its abstract model.
It works as long as I do not inheritate the Houdini palette.
But has soon as I inheritate the palette, the colors are not used anymore.
I built this little example to show what I mean (see below)
On the shelf, create a new tool, add the code to it and accept.
Launch the tool.
Then Edit the tool and comment/uncomment line 34.
I also attached pictures so you see the expected result.
The same code (without line #2 and line #34) works well in Maya.
Does anyone know if there is a way to inheritate the palette AND change row colors when using the QTableView with abstract model?
thanks!
from PySide2 import QtGui, QtCore, QtWidgets import hou class Model(QtCore.QAbstractTableModel): def __init__(self): QtCore.QAbstractTableModel.__init__(self) self.tableList = [["Item %02d" % (i+1)] for i in range(5)] def rowCount(self, parent): return len(self.tableList) def columnCount(self, parent): return 1 def data(self, index, role): if (role == QtCore.Qt.DisplayRole): return self.tableList[index.row()] if role == QtCore.Qt.BackgroundRole: return QtGui.QBrush(QtGui.QColor(255, 25+30*index.row(), 75)) class TableView(QtWidgets.QWidget): def __init__(self, parent=None): QtWidgets.QWidget.__init__(self, parent) tableModel = Model() tableView = QtWidgets.QTableView() tableView.setModel(tableModel) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(tableView) self.setLayout(hbox) # comment / uncomment this line to see colors # self.setParent(hou.ui.mainQtWindow(), QtCore.Qt.Window) dialog = TableView() dialog.show()
In Houdini, with line #34
In Houdini, without line #34
In Maya