qstylesheet.txt

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QPushButton>

class Widget : public QWidget
{
    Q_OBJECT
    
public:
    Widget(QWidget *parent = 0);
    ~Widget();
public slots:
//    void onButt();

public:
//    QPushButton *butt;
};

#endif // WIDGET_H





#include "widget.h"
//#include <QFileDialog>

class QString;

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
//    butt = new QPushButton(tr("open"), this);
//    connect(butt, SIGNAL(clicked()), this, SLOT(onButt()));
}

Widget::~Widget()
{
    
}

//void Widget::onButt()
//{
//    QString dir = QFileDialog::getExistingDirectory(this,
//            tr("Choose the directory!"),   tr("../..\../"),
//            QFileDialog::ShowDirsOnly);
//}
//





#include <QtGui>
#include "widget.h"
#include <QApplication>
#include <QPushButton>
#include <QVBoxLayout>
#include <QLabel>
#include <QCheckBox>
#include <QComboBox>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    Widget *w = new Widget;
//************************ Widget背景色彩效果 ************************
    a.setStyleSheet("Widget{background-color: \
                    qlineargradient(x1:0, y1:0, x2:1, y2: 1, \
                                    stop:0 white, stop:0.4 gray, \
                                    stop:1 green);}");
//************************ Widget背景色彩效果 ************************

//    w->setStyleSheet("QPushButton{background-color: gray;}");
//    w->setStyleSheet("QPushButton[text=Butt1]{color: red;}");

    QPushButton *butt1 = new QPushButton("Butt1");
    QPushButton *butt2 = new QPushButton("Butt2");
    QPushButton *butt3 = new QPushButton("Butt3");
    QLabel *label = new QLabel(QObject::trUtf8("选择以下按钮"));
    QCheckBox *checkbox = new QCheckBox(QObject::trUtf8("复选框"));
    QComboBox *combobox = new QComboBox;
    QLineEdit *lineEdit = new QLineEdit;

    label->setStyleSheet("color: rgb(0, 0, 127); \
                          font: 10pt;");
    butt1->setStyleSheet("color: red; \
                         background-color: gray; \
                         image: url(:img/images/qt-front.png);");
    w->setStyleSheet("QPushButton[text=""Butt2""]{ \
                        color: black; \
                        background-color: yellow;} \
                      QPushButton[text=""Butt3""]{ \
                        color: yellow; \
                        background-color: red;} \
                      QPushButton:hover{ \
                        background-color: darkblue;} \
                      QCheckBox::indicator{ \
                        width: 30px; \
                        height: 30px;} \
                      QCheckBox{ \
                        spacing: 8px;} \
                      QCheckBox:hover:!checked{ \
                        color: yellow;} \
                      QCheckBox:checked, QCheckBox:hover{ \
                        color: red;} \
                      QComboBox::drop-down:hover{ \
                        image: url(:img/images/qt-front.png);} \
                      QLineEdit{ \
                        padding: 0px 15px 0px 0px; \
                        color: rgb(127, 0, 63); \
                        background-color: rgb(255, 255, 241); \
                        selection-color: rgb(255, 255, 241); \
                        selection-background-color: rgb(127, 0, 63); \
                        border: 3px groove blue; \
                        border-radius: 10px;}");

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(label);
    layout->addWidget(butt1);
    layout->addWidget(butt2);
    layout->addWidget(butt3);
    layout->addStretch();
    layout->addWidget(checkbox);
    layout->addWidget(combobox);
    layout->addWidget(lineEdit);
    w->setLayout(layout);

    w->show();

    return a.exec();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值