Qt QScrollBar 滑块阴影

huangapple go评论74阅读模式
英文:

Qt QScrollBar slider shadow

问题

你可以如何设置 QScrollBar 滑块的阴影,就像这样所需样式?从 QScrollBar 继承了一个类,配置了与图片中相似的 QStyleSheet,尝试添加 GraphicsEffect,但它被添加到整个 QScrollBar,而不是滑块。

英文:

How can I set the shadow to slider handle of a QScrollBar like this required style?

Inherited a class from QScrollBar, configured QStyleSheet as in the picture, tried to add a GraphicsEffect, but it is added to the whole QScrollBar, but not to the Slider

答案1

得分: 0

不确定是否有帮助,但您可以尝试以下方法,并在从子控件获取样式后应用您的 QGraphicsEffect,甚至将正确的 painter 传递给 drawComplexControl 方法:

https://doc.qt.io/qt-5/qstyle.html#subControlRect

https://doc.qt.io/qt-5/qstyle.html#drawComplexControl

https://doc.qt.io/qt-5/qgraphicseffect.html#draw

我知道您可以访问滑块的 QRect,但不确定这是否能在您的探索中激发灵感。

QRect handleRect = style()->subControlRect(QStyle::CC_ScrollBar, &option, QStyle::SC_ScrollBarSlider, this);
英文:

Not sure if this helps, but you could try with the following methods and apply your QGraphicsEffect after getting the style from the subcontrol, or even passing the right painter to the method drawComplexControl:

https://doc.qt.io/qt-5/qstyle.html#subControlRect

https://doc.qt.io/qt-5/qstyle.html#drawComplexControl

https://doc.qt.io/qt-5/qgraphicseffect.html#draw

I know that you can access to the QRect for the slider, but I don't know if this can inspire you in your quest.

QRect handleRect = style()->subControlRect(QStyle::CC_ScrollBar, &option, QStyle::SC_ScrollBarSlider, this);

huangapple
  • 本文由 发表于 2023年4月13日 20:16:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76005320.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定