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. [SOLVED] Superimpose Qwidget background on QMainWindow background
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Superimpose Qwidget background on QMainWindow background

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.5k Views 1 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.
  • H Offline
    H Offline
    holygirl
    wrote on last edited by
    #1

    I have a mainwindow with a Qwidget as the central widget, which in turn consists of serveral widgets. Both the mainwindow and the central widget have a a background image but I'm not able to superimpose the central widget background on the mainwindow background. The central widget background image is translucent so I should be able to see the foggy background image of the mainwindow. The code I'm using now in the mainwindow is

    @
    QPalette p = palette();
    QPixmap pixmap1("background.jpg");

        QDesktopWidget* desktopWidget = QApplication::desktop();
        QRect rect = desktopWidget->availableGeometry();
    
        QSize size(rect.width() , rect.height());
        QPixmap pixmap(pixmap1.scaled(size));
        p.setBrush(QPalette::Background,  pixmap);
        setPalette(p); 
    

    @

    @
    CentralWidget *cw = new CentralWidget();
    cw->setStyleSheet("background-image: url(bckng.png);");
    @

    Even if I try to set only the central widget background, the image appears as a background for the widgets inside the central widget and not the central widget as a whole.
    I know I have not framed the question very well, but if you are able to understand it, please do help me.
    Thanks.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      Can you attach an image of the result that you are getting, it will be of help.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        holygirl
        wrote on last edited by
        #3

        Umm, please don't laugh at me. How do I attach a local file from my computer?

        1 Reply Last reply
        0
        • H Offline
          H Offline
          holygirl
          wrote on last edited by
          #4

          Instead of a central widget, I used a QLabel, assigned the layouts to it and set the stylesheet. And it worked!

          1 Reply Last reply
          0

          • Login

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