Search code examples
cssstylesheetqpushbuttonqlineedit

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?


Solution

  • 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