Qt Snippet: Set background color of a widget


Is possible to easily set the background color of a widget by changing the palette of widget itself.




The code is very easy as follow:


MyWidget->setAutoFillBackground(true);

// We set a white background color for this example
QPalette FramePalette(MyWidget->palette());
FramePalette.setColor(QPalette::Background, Qt::white);
MyWidget->setPalette(FramePalette);

Please note that for have our custom backgound color showed is need to set the setAutoFillBackground flag to true as the example.

Comments

Popular posts from this blog

Access GPIO from Linux user space

Launch an app from Android shell terminal

Qt 5 and " Failed to load platform plugin 'windows' " error