QT设置窗体标题及背景颜色

1.设置标题*

在widget.cpp文件下的
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget){ }
这个函数中加上setWindowTitle(“标题”);
如:把标题设为计算器
setWindowTitle(“计算器”);

**

2.设置窗体背景颜色

**
在同样的函数中加上
this->setStyleSheet(“background-color:颜色;”);
this->show();

如:要把背景设为粉色
this->setStyleSheet(“background-color:pink;”);
this->show();

如下是我的代码:

 Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
    {
    ui->setupUi(this);
    setWindowTitle("计算器");
    this->setStyleSheet("background-color:pink;");
    this->show();
    }
       

计算器程序是提前写好的
如下是运行结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42153903/article/details/88614562