【问题标题】:How to set Stylesheet for only one side of border in QLineEdit and QPushButton?如何在 QLineEdit 和 QPushButton 中仅为边框的一侧设置样式表?
【发布时间】:2018-07-22 11:40:02
【问题描述】:

我尝试手动创建组合框。因此,行编辑应与(下拉)按钮结合使用。因此我想隐藏行编辑的右边框和按钮的左边框。

我试过这个:

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

我也尝试过:

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

但两者都不起作用。我哪里错了?

【问题讨论】:

    标签: css stylesheet qpushbutton qlineedit


    【解决方案1】:

    我认为只有一个myLineEdit->setStyleSheet("QLineEdit{border-right: none;}"); 不起作用。我们需要设置边框样式、边框宽度和边框颜色。这段代码对我有用:

    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; }" );
    

    你可以在这里看到边框样式部分http://doc.qt.io/qt-5/stylesheet-reference.html

    【讨论】:

      【解决方案2】:
      ui->txtValFloat->setStyleSheet( "QLineEdit{ border-width: 1px; border-style: solid; border-color:  red white black black;border-top-style:none; }" );
      

      你会看到结果。
      也可以看到 :border-bottom-color 边框底部样式 边框底部宽度
      我使用 qt 5.15

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-03-02
        • 2021-08-11
        • 1970-01-01
        • 2011-02-05
        • 1970-01-01
        • 1970-01-01
        • 2021-06-17
        • 1970-01-01
        相关资源
        最近更新 更多