【问题标题】:Qt style sheet syntax doesn't work?Qt 样式表语法不起作用?
【发布时间】:2013-05-27 07:56:46
【问题描述】:

我正在使用 Qt 5.0.1 。我想使用样式表语法来自定义小部件及其元素的功能。

但有些语法如QLineEdit { color: red }

QPushButton#evilButton:pressed {
     background-color: rgb(224, 0, 0);
     border-style: inset;
 }

不工作,编译器报错。

我更改了一些语法并得到了答案。例如:

QPushButton#evilButton {
 background-color: red;
 border-style: outset;
 border-width: 2px;
 border-radius: 10px;
 border-color: beige;
 font: bold 14px;
 min-width: 10em;
 padding: 6px;

}

转换为:

mypushbutton->setStyleSheet("background-color:purple;"
                     "border-style:inset;"
                     "border-width: 4px;"
                     "border-color: green;"
                     "border-radius: 10px;"
                     "font: bold 14px;"
                     "min-width: 10em;"
                     "padding: 6px;"
                     );

实际上我使用了另一个函数来做到这一点。但是我无法更改第一个代码并且不知道该怎么办……我该怎么办?我应该include 什么或其他什么是问题?我使用this页面来学习样式表语法。即使我自己的Qt示例也不起作用,只是错误引发...!!!???

【问题讨论】:

  • 没人能回答我的问题吗?太有必要了……请帮忙

标签: qt stylesheet qtstylesheets


【解决方案1】:

试过你的例子,它适用于 Qt5

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

    this->setStyleSheet(
                "QPushButton#evilButton {"
                "background-color: red;"
                "border-style: outset;"
                "border-width: 2px;"
                "border-radius: 10px;"
                "border-color: beige;"
                "font: bold 14px;"
                "min-width: 10em;"
                "padding: 6px; }"
                );
}

顺便说一句,我将 qss 存储在文件中并从中加载样式

【讨论】:

  • 忘了说。您可以为整个应用程序设置 qss qApp->setStyleSheet("");
猜你喜欢
  • 2015-09-19
  • 1970-01-01
  • 2021-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-27
相关资源
最近更新 更多