[education/rkward] rkward: Change plugin widgets that set their colors to use setStyleSheet, then clear the style sheet to restore the default color.

Nick Panayioto null at kde.org
Fri Oct 29 20:29:56 BST 2021


Git commit 5d64b6d23f19f4307fca2d79838bb6e1e38c7f36 by Nick Panayioto.
Committed on 29/10/2021 at 11:53.
Pushed by tfry into branch 'master'.

Change plugin widgets that set their colors to use setStyleSheet, then clear the style sheet to restore the default color.

This looks the same on light themes and makes dark themes not use white text on white background.

BUG: 389914

M  +2    -6    rkward/misc/getfilenamewidget.cpp
M  +1    -1    rkward/misc/getfilenamewidget.h
M  +2    -4    rkward/misc/rksaveobjectchooser.cpp
M  +1    -1    rkward/misc/rksaveobjectchooser.h
M  +3    -5    rkward/plugin/rkinput.cpp
M  +4    -4    rkward/plugin/rkpluginbrowser.cpp
M  +2    -2    rkward/plugin/rkpluginsaveobject.cpp
M  +3    -4    rkward/plugin/rkvarslot.cpp

https://invent.kde.org/education/rkward/commit/5d64b6d23f19f4307fca2d79838bb6e1e38c7f36

diff --git a/rkward/misc/getfilenamewidget.cpp b/rkward/misc/getfilenamewidget.cpp
index 6b7f1d26..a439b8a4 100644
--- a/rkward/misc/getfilenamewidget.cpp
+++ b/rkward/misc/getfilenamewidget.cpp
@@ -137,11 +137,7 @@ QString GetFileNameWidget::getLocation () {
 	return (edit->url ().url ());
 }
 
-void GetFileNameWidget::setBackgroundColor (const QColor & color) {
+void GetFileNameWidget::setStyleSheet (const QString & style) {
 	RK_TRACE (MISC);
-
-	QPalette palette = edit->lineEdit ()->palette ();
-	palette.setColor (edit->lineEdit ()->backgroundRole (), color);
-	edit->lineEdit ()->setPalette (palette);
+	edit->setStyleSheet(style);
 }
-
diff --git a/rkward/misc/getfilenamewidget.h b/rkward/misc/getfilenamewidget.h
index ecbf1364..71390667 100644
--- a/rkward/misc/getfilenamewidget.h
+++ b/rkward/misc/getfilenamewidget.h
@@ -41,7 +41,7 @@ public:
 /** set the filename/location from outside */
 	void setLocation (const QString &new_location);
 
-	void setBackgroundColor (const QColor & color);
+	void setStyleSheet (const QString &style);
 
 /** retrieves the current location */
 	QString getLocation ();
diff --git a/rkward/misc/rksaveobjectchooser.cpp b/rkward/misc/rksaveobjectchooser.cpp
index 5d53111d..157f6940 100644
--- a/rkward/misc/rksaveobjectchooser.cpp
+++ b/rkward/misc/rksaveobjectchooser.cpp
@@ -194,12 +194,10 @@ void RKSaveObjectChooser::updateState () {
 	}
 }
 
-void RKSaveObjectChooser::setBackgroundColor (const QColor &color) {
+void RKSaveObjectChooser::setStyleSheet (const QString &style) {
 	RK_TRACE (MISC);
 
-	QPalette palette = name_edit->palette ();
-	palette.setColor (name_edit->backgroundRole (), color);
-	name_edit->setPalette (palette);
+	name_edit->setStyleSheet(style);
 }
 
 QString RKSaveObjectChooser::currentBaseName () const {
diff --git a/rkward/misc/rksaveobjectchooser.h b/rkward/misc/rksaveobjectchooser.h
index c5da85c8..3cc56a85 100644
--- a/rkward/misc/rksaveobjectchooser.h
+++ b/rkward/misc/rksaveobjectchooser.h
@@ -37,7 +37,7 @@ public:
 	QString currentBaseName () const;
 	bool isOk () const;
 	void setBaseName (const QString &name);
-	void setBackgroundColor (const QColor &color);
+	void setStyleSheet (const QString &style);
 	RObject* rootObject () const { return root_object; };
 	void setRootObject (RObject* new_root);
 private slots:
diff --git a/rkward/plugin/rkinput.cpp b/rkward/plugin/rkinput.cpp
index fdbab36a..a1a03ebd 100644
--- a/rkward/plugin/rkinput.cpp
+++ b/rkward/plugin/rkinput.cpp
@@ -96,17 +96,15 @@ void RKInput::updateColor () {
 	if (!widget) widget = textedit;
 	RK_ASSERT (widget);
 
-	QPalette palette = widget->palette ();
 	if (isEnabled ()) {
 		if (isSatisfied ()) {
-			palette.setColor (widget->backgroundRole (), QColor (255, 255, 255));
+			widget->setStyleSheet("");
 		} else {
-			palette.setColor (widget->backgroundRole (), QColor (255, 0, 0));
+			widget->setStyleSheet("background: red; color: black");
 		}
 	} else {
-		palette.setColor (widget->backgroundRole (), QColor (200, 200, 200));
+		widget->setStyleSheet("background: rgb(200, 200, 200); color: black");
 	}
-	widget->setPalette (palette);
 }
 
 void RKInput::requirednessChanged (RKComponentPropertyBase *) {
diff --git a/rkward/plugin/rkpluginbrowser.cpp b/rkward/plugin/rkpluginbrowser.cpp
index 9612acb5..ff862d16 100644
--- a/rkward/plugin/rkpluginbrowser.cpp
+++ b/rkward/plugin/rkpluginbrowser.cpp
@@ -184,14 +184,14 @@ void RKPluginBrowser::updateColor () {
 
 	if (isEnabled ()) {
 		if (status == RKComponentBase::Satisfied) {
-			selector->setBackgroundColor (QColor (255, 255, 255));
+			selector->setStyleSheet (QString (""));
 		} else if (status == RKComponentBase::Processing) {
-			selector->setBackgroundColor (QColor (255, 255, 0));
+			selector->setStyleSheet (QString ("background: yellow; color: black"));
 		} else {
-			selector->setBackgroundColor (QColor (255, 0, 0));
+			selector->setStyleSheet (QString ("background: red; color: black"));
 		}
 	} else {
-		selector->setBackgroundColor (QColor (200, 200, 200));
+		selector->setStyleSheet (QString ("background: rgb(200, 200, 200); color: black"));
 	}
 }
 
diff --git a/rkward/plugin/rkpluginsaveobject.cpp b/rkward/plugin/rkpluginsaveobject.cpp
index 7c084a99..52b9d867 100644
--- a/rkward/plugin/rkpluginsaveobject.cpp
+++ b/rkward/plugin/rkpluginsaveobject.cpp
@@ -82,8 +82,8 @@ RKPluginSaveObject::~RKPluginSaveObject () {
 void RKPluginSaveObject::update () {
 	RK_TRACE (PLUGIN);
 
-	if (isSatisfied ()) selector->setBackgroundColor (QColor (255, 255, 255));
-	else selector->setBackgroundColor (QColor (255, 0, 0));
+	if (isSatisfied ()) selector->setStyleSheet(QString(""));
+	else selector->setStyleSheet(QString("background: red; color: black"));
 	changed ();
 }
 
diff --git a/rkward/plugin/rkvarslot.cpp b/rkward/plugin/rkvarslot.cpp
index bc250b25..6a2ae601 100644
--- a/rkward/plugin/rkvarslot.cpp
+++ b/rkward/plugin/rkvarslot.cpp
@@ -183,15 +183,14 @@ void RKVarSlot::updateLook () {
 
 	QPalette palette = list->palette ();
 	if (!isSatisfied ()) {		// implies that it is enabled
-		palette.setColor (QPalette::Base, QColor (255, 0, 0));
+		list->setStyleSheet(QString("background: red; color: black"));
 	} else {
 		if (isEnabled ()) {
-			palette.setColor (QPalette::Base, QColor (255, 255, 255));
+			list->setStyleSheet(QString(""));
 		} else {
-			palette.setColor (QPalette::Base, QColor (200, 200, 200));
+			list->setStyleSheet(QString("background: rgb(200, 200, 200); color: black"));
 		}
 	}
-	list->setPalette(palette);
 }
 
 void RKVarSlot::changeEvent (QEvent* event) {


More information about the rkward-tracker mailing list