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 set a full background for the main widget

How to set a full background for the main widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 155 Views
  • 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 ManiRon
    #1

    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

    Pl45m4P 1 Reply Last reply
    0
    • ManiRonM ManiRon

      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

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @maniron

      With stylesheet:

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

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      4

      • Login

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