Qt 使用setStyleSheet

#include "widget.h"
#include "ui_widget.h"

#include 

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    QPushButton* button = new QPushButton("按钮", this);
    button->setText("按钮");
    button->setFixedSize(200, 200);
    button->setStyleSheet("QPushButton {"
                          "background-color: red;"
                          "border-radius: 100px;"
                          "}"
                          "QPushButton:hover {"
                          "background-color: green;"
                          "}"
                          "QPushButton:pressed {"
                          "background-color: blue;"
                          "}"
                          "QPushButton:!hover:!pressed {"
                          "background-color: red;"
                          "}");

    QFont* font = new QFont("Arial", 20, QFont::Bold);
    button->setFont(*font);

    // 设置控件位置
    button->move(100, 50);

}

Widget::~Widget()
{
    delete ui;
}

你可能感兴趣的:(Qt,编程,qt,c++)