Results 1 to 2 of 2

Thread: QTreeView Stylesheet: alternate-background-color ignored (QT-5.2.1)

  1. #1
    Join Date
    Apr 2014
    Posts
    1
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11

    Question QTreeView Stylesheet: alternate-background-color ignored (QT-5.2.1)

    I have created a very simple application using the Qt Creator (basically a main window with a QTreeView inside + a couple rows).
    It runs fine except the alternate-background-color is totally ignored.

    Screen Shot 2014-04-09 at 12.53.57 am.png

    Here's the code. I also tried putting the style sheet using the QT Designer but it didn't make a difference.
    Can anyone tell me what's wrong?

    Qt Code:
    1. const char *STYLE_SHEET =
    2. "QTreeView"
    3. "{"
    4. "color: #000000;"
    5. "background-color: #B6B6B6;"
    6. "alternate-background-color: #FFFFFF;"
    7. "selection-color: #FF0000;"
    8. "selection-background-color: #7FB3E6;"
    9. "}";
    10. int main(int argc, char *argv[])
    11. {
    12. QApplication a(argc, argv);
    13. a.setStyleSheet(STYLE_SHEET);
    14. QStandardItem *root = m.invisibleRootItem();
    15. root->appendRow(new QStandardItem("1"));
    16. root->appendRow(new QStandardItem("2"));
    17. root->appendRow(new QStandardItem("3"));
    18. MainWindow w(&m);
    19. w.show();
    20. return a.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. MainWindow::MainWindow(QStandardItemModel *m, QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. ui->treeView->setModel(m);
    8. ui->treeView->expandAll();
    9. }
    To copy to clipboard, switch view to plain text mode 

    I am using QT-5.2.1 under Mac OS X Mavericks.

    Thanks!

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTreeView Stylesheet: alternate-background-color ignored (QT-5.2.1)

    QAbstractItemView::alternatingRowColors() is not enabled by default.

  3. The following user says thank you to ChrisW67 for this useful post:

    CuteTee (9th April 2014)

Similar Threads

  1. Replies: 7
    Last Post: 1st November 2011, 08:55
  2. Replies: 1
    Last Post: 27th May 2011, 21:27
  3. Qt4.7.0 Alternate Row Color from QSS ignored (QTreeView)
    By DancingFirefly in forum Qt Programming
    Replies: 2
    Last Post: 15th February 2011, 23:12
  4. Setting QDial background image using stylesheet
    By dpatel in forum Qt Programming
    Replies: 0
    Last Post: 28th April 2010, 14:13
  5. About the background color of QTreeView itmes
    By yandy in forum Qt Programming
    Replies: 3
    Last Post: 26th March 2009, 16:38

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.