Changing the color of a QFrame in QT

14,559

Solution 1

You need to set the background color of the QFrame.

Set the QFrame's style sheet to the following:

"background-color: rgb(255, 255, 255);"

Solution 2

For Python (PyQt) users:

frame = QFrame(self)
frame.setStyleSheet('background-color: rgb(50,50,50)')  

Solution 3

Set a MainWindow (not the QFrame) StyleSheet like this:

QMainWindow{
   background-color: gray
}
QFrame { 
   border: 5px solid black 
} 

This worked for me:

mainwindow->setStyleSheet("QMainWindow{background-color: gray} QFrame { border: 5px solid black } ");
Share:
14,559
Gage Haas
Author by

Gage Haas

Updated on June 29, 2022

Comments

  • Gage Haas
    Gage Haas almost 2 years

    I have set the color of my main window in QT to be grey.

    ui(new Ui ::MainWindow)
    ui-> setupUi(this)
    this->setStyleSheet("background-color: grey;");
    

    I have tried multiple ways to set the color of the QFrame, however it takes on the default grey color that I have set. One way I tried is below.

    ui->frame->setStyleSheet("color:rgb(255,255,255)");
    

    I have tried to change the color of the QFrame by using the setStyleSheet method but no matter which color I assign it remains grey. I have tried setting the background, border, and color. Is there any way to do this that I am overlooking?

  • Gage Haas
    Gage Haas about 6 years
    The issue I am having with this is that I want to only set the border color of the QFrame. I am attempting to set it like this ui->frame->setStyleSheet("QFrame{border: 5px solid black; }");