Change color edit coloring to use only stylesheets to colorise the line edit only

Sat, 08 Apr 2023 15:08:19 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sat, 08 Apr 2023 15:08:19 +0300
changeset 346
3e3784c4cd3e
parent 345
81cd5dee6d77
child 347
5c655cc006de

Change color edit coloring to use only stylesheets to colorise the line edit only

widgets/colorbutton.cpp file | annotate | diff | comparison | revisions
--- a/widgets/colorbutton.cpp	Sat Apr 08 15:05:57 2023 +0300
+++ b/widgets/colorbutton.cpp	Sat Apr 08 15:08:19 2023 +0300
@@ -1,5 +1,4 @@
 #include <QColorDialog>
-#include <QStyleFactory>
 #include <QHBoxLayout>
 #include "widgets/colorbutton.h"
 
@@ -28,14 +27,12 @@
 	});
 	connect(this->lineEdit, &QLineEdit::textChanged, [&]{
 		const QColor color = this->color();
-		QPalette palette{color};
 		const qreal lightness = color.lightnessF();
 		const QColor foreground = lightness < 0.4 ? Qt::white : Qt::black;
-		const auto style = QStyleFactory::create("Fusion");
-		this->setStyle(style);
-		this->setStyleSheet(QStringLiteral(
-			"*{background-color: %1; color: %2;}"
-		).arg(color.name()).arg(foreground.name()));
+		this->setStyleSheet(
+			QStringLiteral("QLineEdit{background-color: %1; color: %2;}")
+				.arg(color.name())
+				.arg(foreground.name()));
 		Q_EMIT this->colorChanged(this->color());
 	});
 	this->setColor(Qt::black);

mercurial