简体   繁体   English

获取 QLineEdit 的 Qt 默认样式以仅更改其边框颜色

[英]Get Qt default style for QLineEdit to change its border color only

I would like to change the frame color of QLineEdit to red.我想将 QLineEdit 的框架颜色更改为红色。

If I do it like this:如果我这样做:

_lineEdit->setStyleSheet("border : 1px solid red");

the shape of the line edit is changed from its default and the border color change on focus stops happening.线条编辑的形状从其默认值更改,焦点上的边框颜色更改停止发生。

My idea is to take the default values for Qt colors and shapes of QLineEdit and set them using setStyleSheet() but with a border color being changed to red.我的想法是采用 Qt colors 和 QLineEdit 形状的默认值,并使用setStyleSheet()设置它们,但边框颜色更改为红色。 But how can I get the values programmatically?但是如何以编程方式获取值?

I have seen the question How to change QLineEdit border color only , but it is not answered.我已经看到了如何仅更改 QLineEdit 边框颜色的问题,但没有得到解答。

For us it worked to set the properties individually.对我们来说,它可以单独设置属性。 No default values need to be known.不需要知道默认值。
Here is an example where we change the frame color on mouse over:这是一个示例,我们在鼠标悬停时更改框架颜色:

lineEdit->setStyleSheet("QLineEdit {border-width: 1px; border-style: solid; border-color: red;}"
                        "QLineEdit:hover {border-width: 1px; border-style: solid; border-color: blue;}");

I hope this is helpful.我希望这是有帮助的。

Not really understood what you whant, but if I get it you need:不是很明白你想要什么,但如果我明白了,你需要:

line.setStyleSheet("border : 1px solid red; padding-top: 2px; padding-bottom: 2px; border-radius: 2px");

If you need work with object state, look here -> https://doc.qt.io/qt-5/stylesheet-reference.html you need the "List of Pseudo-States" If you need work with object state, look here -> https://doc.qt.io/qt-5/stylesheet-reference.html you need the "List of Pseudo-States"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM