如何解决如何使用 QSS 更改框架样式?
美好的一天。 有关于框架样式的说明,这里https://doc.qt.io/qt-5/qframe.html#setFrameStyle
假设我希望我的按钮有 Box |凹陷。 我如何使用 QSS 做到这一点? 我试着这样做:
frameStyle: box;
background-color: rgb (230,230,230);
border: 1px solid white;
border-right: 2px solid rgb (127,127,127);
border-bottom: 2px solid rgb (127,127);
但它没有帮助,显然我只是不知道代码中的任何一个字。
解决方法
如果您正在寻找 QSS,那么我建议您查看文档中的 stylesheet reference 和 stylesheet examples。在我试图弄清楚如何使用 QSS 设计样式时,它已经帮助了我无数次。
您的样式表应该用大括号括起来,如下所示:
QFrame {
background-color: rgb (230,230,230);
border: 1px solid white;
border-right: 2px solid rgb (127,127,127);
border-bottom: 2px solid rgb (127,127);
}
如果您想为按钮设置样式,我建议您执行以下操作。前面提到的样式表参考和示例中还有更多示例。
这是直接从QSS examples documentation under QPushButton
QPushButton {
border: 2px solid #8f8f91;
border-radius: 6px;
background-color: qlineargradient(x1: 0,y1: 0,x2: 0,y2: 1,stop: 0 #f6f7fa,stop: 1 #dadbde);
min-width: 80px;
}
QPushButton:pressed {
background-color: qlineargradient(x1: 0,stop: 0 #dadbde,stop: 1 #f6f7fa);
}
QPushButton:flat {
border: none; /* no border for a flat push button */
}
QPushButton:default {
border-color: navy; /* make the default button prominent */
}
以这种方式使用 QSS 将允许您更改按钮在不同状态下的外观等。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。