Qt 程序主界面添加背景图片

1、开发环境:Qt5.12.2,QtCreator4.8.2

2、贴图代码,在主程序中编写

#include <QImageReader>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;

    /* 打印查询 QPixmap 支持的图片格式 */
    qDebug() << "Supported formats:" << QImageReader::supportedImageFormats();

    /* 配置背景图片 */
    QPixmap pixmap = QPixmap(":/Resourses/Picture001.jpg").scaled(w.size());
    QPalette palette(w.palette());
    palette.setBrush(QPalette::Background, QBrush(pixmap));
    w.setPalette(palette);
   w.show();
return a.exec(); }
1)查看 Qt 当前支持读取的图片格式 QImageReader::supportedImageFormats();

posted on 2023-01-31 15:28  掌控命运  阅读(360)  评论(0)    收藏  举报

导航