26 this->setColor(color); |
25 this->setColor(color); |
27 } |
26 } |
28 }); |
27 }); |
29 connect(this->lineEdit, &QLineEdit::textChanged, [&]{ |
28 connect(this->lineEdit, &QLineEdit::textChanged, [&]{ |
30 const QColor color = this->color(); |
29 const QColor color = this->color(); |
31 QPalette palette{color}; |
|
32 const qreal lightness = color.lightnessF(); |
30 const qreal lightness = color.lightnessF(); |
33 const QColor foreground = lightness < 0.4 ? Qt::white : Qt::black; |
31 const QColor foreground = lightness < 0.4 ? Qt::white : Qt::black; |
34 const auto style = QStyleFactory::create("Fusion"); |
32 this->setStyleSheet( |
35 this->setStyle(style); |
33 QStringLiteral("QLineEdit{background-color: %1; color: %2;}") |
36 this->setStyleSheet(QStringLiteral( |
34 .arg(color.name()) |
37 "*{background-color: %1; color: %2;}" |
35 .arg(foreground.name())); |
38 ).arg(color.name()).arg(foreground.name())); |
|
39 Q_EMIT this->colorChanged(this->color()); |
36 Q_EMIT this->colorChanged(this->color()); |
40 }); |
37 }); |
41 this->setColor(Qt::black); |
38 this->setColor(Qt::black); |
42 } |
39 } |
43 |
40 |