Home > Enterprise >  Get Qt default style for QLineEdit to change its border color only
Get Qt default style for QLineEdit to change its border color only

Time:07-27

I would like to change the frame color of QLineEdit to red.

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. 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.

CodePudding user response:

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.

CodePudding user response:

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"

  •  Tags:  
  • c qt
  • Related