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

Post a Comment

Popular posts from this blog

Access GPIO from Linux user space

Android: adb push and read-only file system error

Tree in SQL database: The Nested Set Model