I've been hours trying to understand(googling) why my widgets are not shown in a QWidget children I am using as a Windows.
The children are mostly QLabel and some QSliders. The Layout is a QGridlayout
here it is some of my window code:
FenPrincipale::FenPrincipale()
{
this->setWindowTitle("Premier Test");
this->resize(400, 200);
QPalette palette;
palette.setBrush(this->backgroundRole(), QBrush(QImage("images/metal400x200.png")));
this->setPalette(palette);
/*
this->setStyleSheet("background-image: url(images/metal400x200.png); "
"background-position: top left; "
"background-repeat: repeat-xy;"
);
*/
buildChildren();
buildLayout();
this->setLayout(layout_principale);
}
EDIT:
How my children is built
void FenPrincipale::buildChildren()
{
m_title = new QLabel("MonTest");
m_nextPageButton = new QLabel(">");
m_line = new QLabel("Slide here");
m_labelSlider = new QSlider;
m_result = new QLabel("Result");
/*
* Other children is set here...
*/
}
Voilà the result:
I tried changing fonts and other methods to set the background but the background is always shown over the other widgets.
Am I missing something?
It looks like you were close with the style sheet implementation. I get the correct result with the following:
setStyleSheet("QMainWindow { background-image: url(:/images/metal400x200.png) } ");