简体   繁体   English

QT使用样式表来增加滑块手柄的大小

[英]QT Using stylesheets to increase size of slider handle

I'm using QT to subclass QSlider and now I want to make the handle larger. 我正在使用QT继承QSlider的子类,现在我想使手柄更大。 I used SetStylesheet and set a background color and the new size. 我使用SetStylesheet并设置背景颜色和新大小。 When running, the color is set but the size seems to be fixed. 运行时,颜色已设置,但大小似乎是固定的。 I can however adjust the size of the whole QSlider: in that case the groove with handle stays the same size but the surround widget area becomes larger. 但是,我可以调整整个QSlider的大小:在这种情况下,带有手柄的凹槽保持相同的大小,但环绕小部件区域变大。

How can I fix this? 我怎样才能解决这个问题? And furthermore, is there an overview somewhere of the components each QWidget has with a reference to how they can be adjusted by stylesheets? 此外,是否每个QWidget都有组件的概述,以及如何通过样式表进行调整的参考?

Thanks 谢谢

解决方案似乎是在滑块手柄的样式表中设置负边距。

Change handel size:

aSliderProxy = new SliderProxy();
ui->materialVerticalSlider->setStyle(aSliderProxy);

File sliderproxy.h:
#ifndef SLIDERPROXY_H
#define SLIDERPROXY_H

#include <QProxyStyle>

class SliderProxy : public QProxyStyle
{
public:
    int pixelMetric ( PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const
    {
        switch(metric) {
        case PM_SliderThickness  : return 50;
        case PM_SliderLength     : return 50;
        default                         : return (QProxyStyle::pixelMetric(metric,option,widget));
        }
    }
};
#endif // SLIDERPROXY_H

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM