Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

Setting background of HeadData for QTableView is doesn't work

$
0
0
QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const {           if(role ==Qt::BackgroundRole)         {             //if(orientation == Qt::Vertical)             if (orientation == Qt::Horizontal)             switch (section)             {                 case 0:                     *return  QBrush(QColor(Qt::blue));*                 case 1:                     *return  QVariant(QColor(Qt::blue));*                 default:                     return QAbstractTableModel::headerData(section,orientation,role);            }      } } code of part: class TableModel : public QAbstractTableModel {     Q_OBJECT public:     TableModel(int Columns, QStringList Names, QObject *parent = 0);     int rowCount(const QModelIndex &parent) const;     int columnCount(const QModelIndex &parent) const;     QVariant data(const QModelIndex &index, int role) const;     QVariant headerData(int section, Qt::Orientation orientation, int role) const; } class SortFilterProxyModel : public QSortFilterProxyModel {     Q_OBJECT   public:     SortFilterProxyModel(QString typefile, QObject *parent = 0);     QVariant data(const QModelIndex &index, int role) const;     QVariant headerData(int section, Qt::Orientation orientation, int role) const; } int main(int argc, char *argv[]) {     SortFilterProxyModel * proxyModel = new SortFilterProxyModel();     proxyModel->setSourceModel(table);     QTableView * tableView->new QTableView();     tableView->setModel(proxyModel);     return a.exec(); } Above code is not setting background in my program. Setting color or style of fonts of HeadData is working, but background of HeadData is not work in function QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const using return QVariant(QColor(Qt::blue)); or return QBrush(QColor(Qt::blue)); Function setStyleSheet() is working normally, but it is not metting my dynamic setting color on any rows or colums with HeadData. tableView->horizontalHeader()->setStyleSheet("QHeaderView::section{background:skyblue;}"); Can anyone help me? Thanks!

Viewing all articles
Browse latest Browse all 18427

Trending Articles