Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to add the image from resource file for background of the mainwindow
Forum Updated to NodeBB v4.3 + New Features

how to add the image from resource file for background of the mainwindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 1.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ManiRonM Offline
    ManiRonM Offline
    ManiRon
    wrote on last edited by
    #1

    I want to add thge background image of QMainwindow and i want to add from the QRC file how can this be done ?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      racerXali
      wrote on last edited by
      #2

      Image File should be in your qrc file
      Do this in your constructor

      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          QPixmap bkgnd("qrc:/images/xyz.png"); // rightt click on image in qrc to copy its path
          bkgnd = bkgnd.scaled(this->size(), Qt::IgnoreAspectRatio);
          QPalette palette;
          palette.setBrush(QPalette::Background, bkgnd);
          this->setPalette(palette);
      }
      

      For details have a look at this answer:How do I add a background image to the QMainWindow?

      ManiRonM 1 Reply Last reply
      1
      • R racerXali

        Image File should be in your qrc file
        Do this in your constructor

        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
            QPixmap bkgnd("qrc:/images/xyz.png"); // rightt click on image in qrc to copy its path
            bkgnd = bkgnd.scaled(this->size(), Qt::IgnoreAspectRatio);
            QPalette palette;
            palette.setBrush(QPalette::Background, bkgnd);
            this->setPalette(palette);
        }
        

        For details have a look at this answer:How do I add a background image to the QMainWindow?

        ManiRonM Offline
        ManiRonM Offline
        ManiRon
        wrote on last edited by
        #3

        @racerXali i did it but the image is not displaying . Whether it works only when we create an exe

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by SGaist
          #4

          Hi,

          Isn't this the same question as here ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi
            Right click the image and select the :/ syntax and see if that helps.
            alt text

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved