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

How to set a full background for the main widget



  • I am trying to set a full background image for my mainwindow but it is not fitting fully . 0_1565173691140_1.JPG

    Like the image which i have attached . Kindly say how to set a full scaled image as a background for my mainwindow

    My code :

      QPixmap bkgnd("" + QDir::currentPath() +  "./Images/9.jpg");
    bkgnd = bkgnd.scaled(this->size(), Qt::IgnoreAspectRatio);
    QPalette palette;
    palette.setBrush(QPalette::Background, bkgnd);
    this->setPalette(palette);
    

    0_1565174089368_1.JPG



  • @maniron

    With stylesheet:

    QString stylesheet = QString("QMainWindow { border-image: url(%1) 0 0 0 0 stretch }").arg(YOUR_IMG_PATH);
    this->setStylesheet(stylesheet);
    

Log in to reply