1.十六进制->rgb
QString text = "#7590cd";
int r = text.mid(1, 2).toInt(nullptr, 16);
int g = text.mid(3, 2).toInt(nullptr, 16);
int b = text.mid(5, 2).toInt(nullptr, 16);
QString style = QString("background-color: rgb(%1, %2, %3);").arg(r).arg(g).arg(b);
ui->label->setStyleSheet(style);
2.QColor->rgb
QColor newColor = QColorDialog::getColor(oldColor, this, tr("选择颜色"));
if (newColor.isValid() && newColor != oldColor) {
ui->lineEdit->setText(newColor.name());
QString style = QString("background-color: rgb(%1, %2, %3);").arg(newColor.red()).arg(newColor.green()).arg(newColor.blue());
ui->label->setStyleSheet(style);
}