Hello,
I have a project with a QTableView and a corresponding QAbstractTableModel. I have implemented a filter that can be applied to multiple columns. I need the column color (just the header section, not the entire column of the QTableView) to change if a filter is being applied to that column. I've made a couple of attempts and did not succeed. I'm starting to wonder if this is even possible.
I tried setting the stylesheet, but it didn't do anything:
{
background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 #00FF00, stop:1 #004C00);
}
QHeaderView::section:selected
{
background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 #00FF00, stop:1 #004C00);
}
To copy to clipboard, switch view to plain text mode
I tried connecting the sectionClicked(int) signal in the QHeaderView to the model, to store the lastColumn clicked, and use this in headerData() to return a color if the role== Qt::BackgroundColorRole, but this did not work either.
QVariant OrderTableModel
::headerData(int section, Qt
::Orientation orientation,
int role
) const {
...
else if (role == Qt::BackgroundColorRole)
{
if (orientation == Qt::Horizontal) {
if (section == m_nSectionClicked)
{
}
else
{
}
}
}
...
}
QVariant OrderTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
...
else if (role == Qt::BackgroundColorRole)
{
if (orientation == Qt::Horizontal) {
if (section == m_nSectionClicked)
{
return QBrush(Qt::darkBlue);
}
else
{
return QBrush(Qt::black);
}
}
}
...
}
To copy to clipboard, switch view to plain text mode
Bookmarks