From 8512ed1a06888a98f71367f4ac3da3f6edc945c3 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 3 Feb 2018 08:02:05 +0100 Subject: Implement alternating row colors Once again, surprisingly difficult, as you can see on the number of changed files. Coding the configuration options wasn't that difficult, but actually using them was. As it turned out, the default style on Windows doesn't use QApplication::palette() at all, though it does honor setAlternatingRowColors(). It just doesn't use the palette colors, but style sheets. Took me a while to figure out. So, there's always another layer of indirection: First, add all QTreeViews to Globals::views, then create a helper to set the style sheet. --- helper.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'helper.cpp') diff --git a/helper.cpp b/helper.cpp index c3bc118..08b8532 100644 --- a/helper.cpp +++ b/helper.cpp @@ -11,8 +11,10 @@ #include #include #include +#include #include "helper.h" +#include "globals.h" namespace Helper { const QString md5Sum(const QString &path){ @@ -155,6 +157,21 @@ namespace Helper { return QIcon(QPixmap::fromImage(img)); } + void setAlternatingRowColors(){ + QSettings s; + bool alternate = s.value("alternatecolors").toBool(); + if(alternate){ + QColor b = s.value("basecolor").value(); + QColor a = s.value("altcolor").value(); + QString style = QString("background-color: rgb(%1,%2,%3);alternate-background-color: rgb(%4,%5,%6);").arg(b.red()).arg(b.green()).arg(b.blue()).arg(a.red()).arg(a.green()).arg(a.blue()); + QVector views = Globals::instance()->views(); + for(QTreeView *v : views){ + v->setAlternatingRowColors(true); + v->setStyleSheet(style); + } + } + } + Duration::Duration() : mHours(0), mMinutes(0), mSeconds(0) {} Duration::Duration(qint64 seconds){ -- cgit v1.2.3-70-g09d2