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?
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);"
For Python (PyQt) users:
frame = QFrame(self)
frame.setStyleSheet('background-color: rgb(50,50,50)')
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 } ");
This troubled me quite some time. Before setting the actual stylesheet unset it first:
ui->frame->setStyleSheet("");
ui->frame->setStyleSheet("background-color: rgb(255,255,255)");
For more customisation options have a look at https://doc.qt.io/qt-5/stylesheet-examples.html and for larger projects you might want to think about setting up global stylesheets for your app.
这对我有用:
ui->frame->setStyleSheet("background-color: rgb(251, 255, 206);");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.