Initialization of QPalette.
-
Hello team,
I was going through demo code of QPalette. Below is the code.
QColor color = QColorDialog::getColor(QColor(m_label->text()),this,"Select color",QColorDialog::ShowAlphaChannel);
if(color.isValid())
{
QPalette palette = m_label->palette();
palette.setColor(QPalette::Window,color);
m_label->setPalette(palette);
m_label->setText(color.name());
}Now instead of initializing QPalette like this QPalette palette = m_label->palette();
if I do like this,
QPalette palette;
palette.setColor(QPalette::Window,color);
m_label->setPalette(palette);
m_label->setText(color.name());What is the difference in both initialization?
-
@ankit-thakar said in Initialization of QPalette.:
What is the difference in both initialization?
The first one grabs the current
palette
fromm_label
, sets the color tocolor
and sets the edited palette to the label again.
Everything else will be the same asm_labels
palette.The second one creates a new palette with default parameters and
color
color (No additional brush, shadow or anything else)