Good morning all,
does anyone know, how to color the QTableViews header by using the standard delegate in Qts MV architecture? I tried this by using the roles as it does in the data() method, but in the headerData() nothing happens :-(
QVariant SchulungsplanModel
::headerData(int section, Qt
::Orientation orientation,
int role
) const {
// HORIZONTAL HEADER: (timeline)
if (orientation == Qt::Horizontal)
{
if(role == Qt::BackgroundRole)
if(role == Qt::DisplayRole)
{
if (section < m_horizontalHeaderList.size())
return m_horizontalHeaderList.at(section);
}
}
// VERTICAL HEADER: PUs
if (orientation == Qt::Vertical)
{
if(role == Qt::DisplayRole)
{
if (section < m_verticalHeaderList.size())
return m_verticalHeaderList.at(section);
}
}
}
QVariant SchulungsplanModel::headerData(int section, Qt::Orientation orientation, int role) const
{
// HORIZONTAL HEADER: (timeline)
if (orientation == Qt::Horizontal)
{
if(role == Qt::BackgroundRole)
return QVariant(QBrush(QColor(Qt::green), Qt::SolidPattern));
if(role == Qt::DisplayRole)
{
if (section < m_horizontalHeaderList.size())
return m_horizontalHeaderList.at(section);
}
}
// VERTICAL HEADER: PUs
if (orientation == Qt::Vertical)
{
if(role == Qt::DisplayRole)
{
if (section < m_verticalHeaderList.size())
return m_verticalHeaderList.at(section);
}
}
return QAbstractTableModel::headerData(section, orientation, role);
}
To copy to clipboard, switch view to plain text mode
Bookmarks