QSlider增加手柄尺寸

Pre*_*nix 3 c++ qt qslider qstylesheet

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

我有一个像这样的滑块: 我有这样的滑块

我希望增加其手柄的高度,如下图所示,但我猜不出该怎么做。也许唯一的方法是继承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;}"
            );
Run Code Online (Sandbox Code Playgroud)

sco*_*nov 6

使用此样式表:

.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;
}
Run Code Online (Sandbox Code Playgroud)

它将产生以下内容:

图片

请注意,通过将min-height和设置max-height为相同的值可以使滑块的高度恒定。