【问题标题】:How to create a QPushButtton with 2 borders using style sheets?如何使用样式表创建具有 2 个边框的按钮?
【发布时间】:2014-04-10 23:19:36
【问题描述】:

我正在尝试使用样式表来自定义 QPushButton。使用以下样式表,我创建了一个带有灰色背景和黑色边框的按钮:

 background-color: rgb(97, 97, 97); 
 border-style: outset;
 border-width: 1px;
 border-color: rgb(0, 0, 0);
 border-radius: 4px;
 color:rgb(255, 255, 255);

我想使用样式表在按钮周围添加第二个边框。我尝试设置填充颜色,但这似乎没有任何作用。是否可以添加第二个边框?

【问题讨论】:

    标签: qt stylesheet


    【解决方案1】:

    如果您只想使用样式表,那可能是不可能的。

    类似的解决方法是将border-style改为double,例如

    background-color: rgb(97, 97, 97);
    border-style: double;
    border-width: 3px;
    border-color: rgb(0, 0, 0);
    border-radius: 4px;
    color:rgb(255, 255, 255);
    

    全部available borders

    关于填充,无法为其设置颜色。解释一下它的样子是here

    【讨论】:

      【解决方案2】:

      用 QFrame 包裹按钮,并设置 QFrame 和 QPushButton 的样式。

      //    ------Widget------
      //      ------hbox----------
      //        ------QFrame---------
      //          ------frameLayout-----
      //            ------QPushButton-----
      
      QHBoxLayout * hbox = new QHBoxLayout;
      QFrame * frame = new QFrame;
      QPushButton * button = new QPushButton("Double Border Button");
      QHBoxLayout * frameLayout = new QHBoxLayout;
      frameLayout->addWidget(button);
      frame->setLayout(frameLayout);
      hbox->addWidget(frame);
      this->setLayout(hbox);
      

      希望对您有所帮助。

      【讨论】:

        猜你喜欢
        • 2023-01-16
        • 2020-01-19
        • 2018-02-16
        • 1970-01-01
        • 2015-09-01
        • 2017-10-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多