how to set different background colors for rows in qtreeview
-
https://www.qtcentre.org/threads/61716-Set-the-color-of-a-row-in-a-qtreeview
found one here. Kind of messy. -
check this is code to set same color in column in Qtableview ..might be helpful
QAbstractItemModel* table1 = ui.tableView_1->model(); for (int row = 0; row < table1->rowCount(); ++row) { for (int column : {0, 1, 2) table1->setData(table1->index(row, column), QBrush(QColor(240, 248, 255)), Qt::BackgroundRole); -
check this is code to set same color in column in Qtableview ..might be helpful
QAbstractItemModel* table1 = ui.tableView_1->model(); for (int row = 0; row < table1->rowCount(); ++row) { for (int column : {0, 1, 2) table1->setData(table1->index(row, column), QBrush(QColor(240, 248, 255)), Qt::BackgroundRole); -
Hi
But what model type is it?
If a custom model it will be handled by the data function when asked for the BackgroundRole. -
Hi
But what model type is it?
If a custom model it will be handled by the data function when asked for the BackgroundRole. -
@JoeCFD said in how to set different background colors for rows in qtreeview:
QFileSystemModel of qt 5.15.2
So why should this model handle setData() with Qt::BackgroundRole? btw: setData() has a return value...
-
@JoeCFD said in how to set different background colors for rows in qtreeview:
QFileSystemModel of qt 5.15.2
So why should this model handle setData() with Qt::BackgroundRole? btw: setData() has a return value...
@Christian-Ehrlicher That is how it works. If qtreewidget is used, it has setData. But qtreeview does not have setData and its properties are manipulated with model.
-
@JoeCFD said in how to set different background colors for rows in qtreeview:
QFileSystemModel
This model only handles
Qt::EditRole.You can use
RoleMaskProxyModelfrom this library to support other roles. See this example -
@JoeCFD said in how to set different background colors for rows in qtreeview:
QFileSystemModel
This model only handles
Qt::EditRole.You can use
RoleMaskProxyModelfrom this library to support other roles. See this example