You need to be more specific about what widgets will have the background applied. At the moment you are probably setting a background on the main widget and this cascades to all widgets placed on it.
#include <QtGui>
#include <QDebug>
Q_OBJECT
public:
central->setObjectName("centralWidget");
// this
central->setStyleSheet("#centralWidget { background: url('gradient.png'); }" );
// not this
// central->setStyleSheet("* { background: url('gradient.png'); }" );
layout->addWidget(label1);
layout->addWidget(label2);
central->setLayout(layout);
setCentralWidget(central);
}
public slots:
private:
};
int main(int argc, char *argv[])
{
MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
#include <QDebug>
class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p) {
QWidget *central = new QWidget(this);
central->setObjectName("centralWidget");
// this
central->setStyleSheet("#centralWidget { background: url('gradient.png'); }" );
// not this
// central->setStyleSheet("* { background: url('gradient.png'); }" );
QVBoxLayout *layout = new QVBoxLayout(central);
QLabel *label1 = new QLabel("Label 1", this);
QLabel *label2 = new QLabel("Label 2", this);
layout->addWidget(label1);
layout->addWidget(label2);
central->setLayout(layout);
setCentralWidget(central);
}
public slots:
private:
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks