trangan
trangan

Reputation: 361

How to set Stylesheet for only one side of border in QLineEdit and QPushButton?

I tried to create a combo box manually. So a line edit should be combined with a (dropdown) push button. Therefore I want to hide the right border of line edit and left border of push button.

I tried with this:

myLineEdit->setStyleSheet("QLineEdit{border-right: none;}");
myPushButton->setStyleSheet("QPushButton{border-left:none;}");

I also tried with:

myLineEdit->setStyleSheet("QLineEdit{border: 1px 1px 0px 1px;}");

But both did not work. Where am I wrong?

Upvotes: 3

Views: 10308

Answers (2)

HuaiSheng Lin
HuaiSheng Lin

Reputation: 31

ui->txtValFloat->setStyleSheet( "QLineEdit{ border-width: 1px; border-style: solid; border-color:  red white black black;border-top-style:none; }" );

you will see result.
also can see :border-bottom-color border-bottom-style border-bottom-width
I use qt 5.15

Upvotes: 3

gnase
gnase

Reputation: 638

I think only one myLineEdit->setStyleSheet("QLineEdit{border-right: none;}"); does not work. We need to set border style, border width and border color. This code worked for me:

myLineEdit->setStyleSheet( "QLineEdit{ border-width: 1px; border-style: solid; border-color: black white black black; }" );
myPushButton->setStyleSheet( "QAbstractButton{ border-width: 1px; border-style: solid; border-color: black black black white; }" );

you can see border-style part here http://doc.qt.io/qt-5/stylesheet-reference.html

Upvotes: 5

Related Questions