• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4510
  • Last Modified:

Set Background in Main Window only using QT

I am new to QT and am trying to set the background for the main window without the child widgets being affected.

I am using QT creator and the GUI and the way I have found so far is to right click on the form, Choose "change stylesheet" and set the background url.

However this affects all widgets on the form giving them the same background.

How do I avoid this?
0
dbdp
Asked:
dbdp
  • 3
  • 2
1 Solution
 
irfan_omairCommented:
you can try this

QPalette pal = a->palette();
pal.setColor(QPalette::Window, Qt::white);
myWindow->setPalette(pal);

Or you can also do it using Stylesheet in your code

MainWindow::MainWindow(QWidget *parent) : QWidget(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setStyleSheet("background-color: black;");
}


Let me know if you still unable to do it

regards,
Irfan Omair
0
 
dbdpAuthor Commented:
My Mistake, My problem is that when I set a background image it propagates to all the widgets on the form
0
 
irfan_omairCommented:
Hey wait, Are you trying to set background image on the main window or background color??
0
 
dbdpAuthor Commented:
Background image - but I want to limit it to main window only!
0
 
irfan_omairCommented:
dbdp:
Sorry I was on vacation.
are you still having this problem?
If not can you have look of the license wizard example which is available in Qt Demos and Example.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now