Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Allow user to change table color during run-time
cherple last edited by
Hi, i have a the following code:
table->setStyleSheet("background-color: rgba(255, 255, 255, 10);");
Now, i want to allow user to change the colors during run time, and i have 3 variables color_red, color_blue, color_green. The user writes the color to these 3 variables, is there any simplier way i can put these variables into the stylesheet?
Currently what i did was:
QString tempColor = "background-color: rgba("
Is there any way i can do these appends in one like?
What you are looking for is:
QString tempColor = QString("background-color: rgba(%1,%2,%3,10)").arg(color_red).arg(color_green).arg(color_blue);
Oh and you could even skip the
tempColorand assign directly like,
And just for the furture, you can use
QString::arg()to parse arguments like your would use
sprintf(). Instead of things like %d, %s, etc, you use argument numbers, i.e. %1 %2 %3 %4 ... and then each call to .arg() at the end replaces #X with the argument.