Results 1 to 11 of 11

Thread: HeaderView BackgroundColor

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: HeaderView BackgroundColor

    Yes the application change a little bit with -style plastque.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: HeaderView BackgroundColor

    Hmm... a little bit? BTW. What does your "MainWindow" class inherit from? If not from QAbstractItemView or one of its subclasses then that's why your header doesn't change colour

  3. #3
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: HeaderView BackgroundColor

    try passing a QBrush instead of a QColor?
    (and use Qt::BackgroundRole, Qt::BackgroudColorRole is obsolete)

    HTH

  4. #4
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: HeaderView BackgroundColor

    My "MainWindow" class inherit from QMainWindow see code snippet.
    Qt Code:
    1. #include <QtGui>
    2. #include <QtOpenGL>
    3. #include <QtSql>
    4.  
    5. #include "mainwindow.h"
    6. #include "glwidget.h"
    7. #include "customsqlmodel.h" //CustomSqlModel
    8.  
    9. MainWindow::MainWindow(QWidget *parent)
    10. :QMainWindow(parent)
    11. {
    12.  
    13. setupUi(this);
    14.  
    15. setWindowIcon(QIcon(":/images/triple20.png"));
    16. connect(actionInfo, SIGNAL(triggerred()), this, SLOT(info()));
    17. connect(actionTriple_S, SIGNAL(triggered()), this, SLOT(triple()));
    18. connect(actionAfsluiten, SIGNAL(triggered()), this, SLOT(exit()));
    19. connect(pbVerzend, SIGNAL(clicked()), this, SLOT(verzend()));
    20. connect(pbVerbind, SIGNAL(clicked()), this, SLOT(verbind()));
    21.  
    22. model = new CustomSqlModel(this);
    23. model->setTable("planning");
    24. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    25. model->select();
    26.  
    27. model->setHeaderData(0, Qt::Horizontal, tr("Categorie")); //HeaderLabels
    28. model->setHeaderData(1, Qt::Horizontal, tr("Klant"));
    29. model->setHeaderData(2, Qt::Horizontal, tr("Plaats"));
    30. model->setHeaderData(3, Qt::Horizontal, tr("Geschat pot"));
    31. model->setHeaderData(4, Qt::Horizontal, tr("Bezocht"));
    32. model->setHeaderData(5, Qt::Horizontal, tr("Planning"));
    33.  
    34. view->setModel(model);
    35.  
    36. // etc....
    37.  
    38. }
    To copy to clipboard, switch view to plain text mode 
    My CustomSqlModel see code snippet h file.
    Qt Code:
    1. #ifndef CUSTOMSQLMODEL_H
    2. #define CUSTOMSQLMODEL_H
    3.  
    4. #include <QSqlTableModel>
    5. #include <QVariant>
    6. #include <QModelIndex>
    7.  
    8. class CustomSqlModel : public QSqlTableModel
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. CustomSqlModel(QObject *parent = 0);
    14.  
    15. QVariant data(const QModelIndex &item, int role) const;
    16. QVariant headerdata(int section, Qt::Orientation orientation, int role = Qt::BackgroundColorRole) const;
    17. //int rowCount(const QModelIndex &parent = QModelIndex()) const;
    18. };
    19.  
    20. #endif
    To copy to clipboard, switch view to plain text mode 

    My CustomSqlModel see code snippet.cpp file
    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "customsqlmodel.h"
    4.  
    5. CustomSqlModel::CustomSqlModel(QObject *parent)
    6. : QSqlTableModel(parent)
    7. {
    8. }
    9.  
    10. QVariant CustomSqlModel::data(const QModelIndex &index, int role) const
    11. {
    12. QVariant val0 = QSqlTableModel::data(index, role);
    13. if (role == Qt::BackgroundColorRole && index.column() == 0)
    14. {
    15. return qVariantFromValue(QColor(Qt::gray));
    16. }
    17.  
    18. // etc....
    19.  
    20. return val0;
    21.  
    22. }
    23.  
    24. QVariant CustomSqlModel::headerdata(int section, Qt::Orientation orientation, int role) const
    25. {
    26. if(role == Qt::BackgroundColorRole)
    27. {
    28. return (QColor(Qt::yellow));
    29. }
    30. return QVariant();
    31.  
    32. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: HeaderView BackgroundColor

    yes, and...
    what is your question?

    did you try returning a QBrush instead of a QColor?

Similar Threads

  1. Replies: 1
    Last Post: 17th March 2008, 14:02
  2. Backgroundcolor QLCDNumber in Windows?
    By Teuniz in forum Qt Programming
    Replies: 4
    Last Post: 30th August 2006, 15:09
  3. [ItemView] Bug in headerview
    By lauranger in forum Qt Programming
    Replies: 3
    Last Post: 14th August 2006, 11:55
  4. QTreeWidget backgroundcolor
    By vmferreira in forum Qt Programming
    Replies: 5
    Last Post: 9th August 2006, 20:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.