Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to stretch the background image?



  • Hi.
    How to stretch the background image?
    The image does not stretch.

        QPalette Pal(palette());
        //QImage background(":/Images/Images/splash-background.png");
        QImage background(":/Images/Images/ico-qr.png");
        Pal.setBrush(QPalette::Background, background);
        this->setAutoFillBackground(true);
        this->setPalette(Pal);
    

    or

     this->setStyleSheet("background-image: url(:/Images/Images/ico-qr.png); ");
    

  • Lifetime Qt Champion

    Hi,

    See this thread for inspiration.



  •     QPixmap bkgnd(":/Images/Images/splash-background.png");
        bkgnd = bkgnd.scaled(size(), Qt::IgnoreAspectRatio);
        QPalette p = palette(); //copy current, not create new
        p.setBrush(QPalette::Background, bkgnd);
        setPalette(p);
    

Log in to reply