QSlider增加手柄大小

5
我急需增加滑块手柄的大小,但没有css选项可以做到这一点(styleSheet())。Qt文档中的默认示例也没有帮助我。
我有一个像这样的滑块:I have slider like this 我希望增加它的手柄高度,如下面的解释图所示,但我无法猜测如何实现。可能唯一的方法是子类化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;}"
            );
2个回答

11

使用这个样式表:

.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;
}

它将产生以下内容:

image

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


2

我将您的代码复制到了Qt Designer中的一个表单中。滑块控制器看起来足够大。

但是,当添加布局时,整个滑块的尺寸不够大,无法显示完整的控制器。我只需添加以下内容:

QSlider {
    height: 80px;
}

并获得以下结果:

表单滑块截图


是的,但我不需要增加进度条的高度,这就是重点。 - Preonix

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接