【问题标题】:QSlider increase handle sizeQSlider 增加手柄尺寸
【发布时间】:2018-05-21 09:04:25
【问题描述】:

我非常需要增加滑块的句柄大小,但没有 css 选项可以做到这一点(styleSheet())。 Qt 文档中的默认示例也对我没有帮助。

我有一个这样的滑块:

我希望增加其手柄的高度,如下面的解释图所示,但我不知道该怎么做。可能唯一的方法是继承 QAbstractSlider?

这是我的代码中的样式表:

                "QSlider::groove:horizontal {"
                "border: 1px solid #999999;"
                "height: 32px;" /* the groove expands to the size of the slider by default. by giving it a height, it has a fixed size */
                "background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4);"
                "margin: 2px 0; }"
            "QSlider::handle:horizontal {"
                "background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 #8f8f8f);"
                "border: 1px solid #5c5c5c;"
                "width: 40px;"
                "margin: -20px 0;" /* handle is placed by default on the contents rect of the groove. Expand outside the groove */
                "border-radius: 3px;}"
            );

【问题讨论】:

    标签: c++ qt qslider qstylesheet


    【解决方案1】:

    使用这个样式表:

    .QSlider {
        min-height: 68px;
        max-height: 68px;
        background: #5F4141;
    }
    
    .QSlider::groove:horizontal {
        border: 1px solid #262626;
        height: 5px;
        background: #393939;
        margin: 0 12px;
    }
    
    .QSlider::handle:horizontal {
        background: #22B14C;
        border: 5px solid #B5E61D;
        width: 23px;
        height: 100px;
        margin: -24px -12px;
    }
    

    它将产生以下内容:

    请注意,通过将min-heightmax-height 设置为相同的值,滑块的高度将保持不变。

    【讨论】:

      【解决方案2】:

      我将您的确切代码复制到 Qt Designer 中的表单中。滑块手柄看起来足够大。

      但是,在添加布局时,整个滑块的大小不足以显示完整的句柄。我只是添加了这个:

      QSlider {
          height: 80px;
      }
      

      得到这个结果:

      【讨论】:

      • 是的,但我不需要增加进度条高度,这就是重点
      猜你喜欢
      • 2020-11-05
      • 1970-01-01
      • 1970-01-01
      • 2015-01-27
      • 2016-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      相关资源
      最近更新 更多