Qt 样式表语法不起作用?

标签 qt stylesheet qtstylesheets

我正在使用 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 示例也不起作用,只会引发错误......!!!???

最佳答案

试过你的例子,它适用于 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 存储在文件中并从中加载样式

关于Qt 样式表语法不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16858235/

相关文章:

c++ - 使用 QT 的最小 OpenGL 离屏渲染

c++ - 任意长度的 BINARY 类型的 QT SQL 数据类型 (QVariant) 映射

c++ - 在 Visual Studio 2019 中使用 Qt 时出错

css - Codeigniter 基本 url 在 header 中不起作用

css - 是否有使用样式表和 next 的 HTML5 <link rel> 属性组合的用例?

qt - 使用 Qt 并行化 OpenCV 处理

qt - Qt 中的样式表、隐藏的小部件和大小

python - 如何从 QComboBox 的弹出窗口中删除白色背景(顶部和底部)?

python - QSS 未应用于 QVBoxLayout 中(复合小部件)中的第一个 QSizeGrip

python - ScrollBar QStyleSheet 显示时带有背景 它应该是透明的