我正在使用 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/