背景图片

.cpp代码:
    QFile file("yinyong.txt");
    file.open(QFile::ReadOnly);
    QTextStream filetext(&file);
    QString stylesheet = filetext.readAll();

    //设置样式
    this->setStyleSheet(stylesheet);


.txt代码:
QMainWindow{   
    background-image:url(zh.jpg);   
    background-origin:content;   
    background-repeat:repeat;   
}   
  
QLabel{   
    color:gray;   
}  

将yinyong.txt和zh.jpg放在运行后生成的文件夹下
运行效果:窗口的背景图片为zh.jpg

你可能感兴趣的:(背景图片)