To insert the color in one of my LCD Number I simply use the instruction:
this->ui->lcdNumber_23->setPalette(Qt::red);
But I can't find how to get the current color that an LCD Number has, I've tried to get the palette but I can't find the get method. The objective is to make a comparison since depending on the current color that the number has, I will put one or the other. Greetings.
QLCDNumber inherits from QWidget and this object has a property called
palette
. Looking there we see that it's a read/write property. The writing is done, as you have rightly commented, withsetPalette
, while the reading is done with the methodpalette
Or, if you don't want to use references and want to copy the object:
As a result of the comment:
Note that when you call
setPalette
you are not passing a palette as such but aQGlobalColor
, which is an enumeration. From that enumeration, the compiler has to create an object of typeQPalete
, if it were not capable, an error would appear at compile time, but this is not the case.If we therefore review the documentation for
QPalette
, we see that it has a constructor that accepts aQt::GlobalColor
. The documentation for that method says the following:That is, based on that color the entire color palette is calculated. And the role that stores the color passed as an argument is
Window
... just retrieve the color associated with that role to get the desired color. For this we have the methodcolor
:And voila, with that you should get the desired color.