Change Qt Title Bar Color with QSS
To change the color of the Qt title bar, you can customize the style using QSS (Qt Style Sheets). Here is a simple example code that sets the background color of the title bar to red:
#include <QApplication>
#include <QMainWindow>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow mainWindow;
mainWindow.setWindowTitle("Custom Title Bar Color");
// 设置标题栏背景颜色为红色
mainWindow.setStyleSheet("QMainWindow::title { background-color: red; }");
mainWindow.show();
return app.exec();
}
In the code above, we use the setStyleSheet method to set the style of the title in QMainWindow, setting the background color to red. You can also modify the color values as needed to achieve a custom title bar color effect.