Table view: custom alternate row colors?



  • how do i get something like this?

    0_1558403894948_Screen Shot 2019-05-20 at 6.57.18 PM.png
    when i try to use a style sheet, like this:

    tracksList->setStyleSheet("alternate-background-color: #bfffbf; background-color: #deffde;");
    

    it colorizes the ENTIRE background including the header (sort-column) bar, and gives me non-platform scroll bars. this is supposed to be a mac (with mac scroll bars):

    0_1558404135796_Screen Shot 2019-05-20 at 7.01.08 PM.png

    I just want the table view background color set, not the sort-column header nor the scroll bars. how?



  • magic!

    0_1558543364465_Screen Shot 2019-05-22 at 9.20.54 AM.png


  • Qt Champions 2018

    try using the item scope tracksList->setStyleSheet("QTableView::item:alternate { background-color: #bfffbf; } QTableView::item { background-color: #deffde; }");



  • holy cats you guys! that worked!

    0_1558455802162_Screen Shot 2019-05-21 at 9.22.59 AM.png



  • okay so the final part is: now that i've got the BG colors lookin sweet, suddenly the SELECTION color is all wiggy. ie: without setting the alt-rows colors, selection looks like this:

    0_1558539378861_Screen Shot 2019-05-22 at 8.33.01 AM.png

    but WITH the alt-rows colors set, it looks like this?

    0_1558539406244_Screen Shot 2019-05-22 at 8.34.50 AM.png

    ie: no actual selection hilight, but the text does turns white?

    I actually need it to have that very dark selection look. I don't see in the doc on style sheets how to accomplish that?



  • @davecotter Hi,
    Use palette instead of stylesheet so you will not have the issue with selection.

    QPalette p = tracksList.palette();
    p.setColor(QPalette::Base, color1);
    p.setColor(QPalette::AlternateBase, color2);
    tracksList.setPalette(p);
    


  • magic!

    0_1558543364465_Screen Shot 2019-05-22 at 9.20.54 AM.png


Log in to reply