Best way to insert background image in Form
-
Dear
I want to know what is the best way (most optimal) to insert a background image on a form.
-
Use stylesheet in Form (border-image property)? Then I need to change the border-image property of all widgets containing the form.
-
Inserted on a label with the image (background-image)
-
other?
Tanks All!!!!
-
-
Just a note:
- Use stylesheet in Form (border-image property)?
- Then I need to change the border-image property of all widgets containing the form.
Style sheets are cascading so if you apply to parent, all childs can be affected.
-
@mrjj said in Best way to insert background image in Form:
are cascading
Tanks for your reply. I know that Style sheets are cascading so if you apply to parent, all childs can be affected. This is the optimal way? 1,2 or 3? Tanks
-
@MarceloGomez Here's some short example for the QBrush-constructor using QImage:
#include <QApplication> #include <QBrush> #include <QHBoxLayout> #include <QPalette> #include <QPushButton> #include <QWidget> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget widget; QPalette palette = widget.palette(); const QBrush brush(QImage(":/ImageFromResources")); palette.setBrush(QPalette::Background, brush); widget.setPalette(palette); QHBoxLayout *layout = new QHBoxLayout(&widget); widget.setLayout(layout); layout->addWidget(new QPushButton(&widget), 0); layout->addWidget(new QWidget(&widget), 1); widget.setVisible(true); return app.exec(); }
As you can see, even if the QPalette is set before adding/parenting new widgets, it's only applied to the widget where you set it. That's because the global default QPalette is used when creating a new instance of a QWidget. Changing the global QPalette would be done using QApplication::setPalette .