从 Qt 中的滚动条中删除箭头
我使用的是小型黑白屏幕,并且需要滚动条只是黑色外框中的黑色滑块。我使用样式表得到了我想要的东西,但在安装时将它们包含在配置中会占用太多空间,所以我无法使用它们。是否可以通过继承 QStyle 或者其他东西来删除箭头? 谢谢
I'm using a small black and white screen and need the scrollbar to just be a black slider in a black outer frame. I got what I wanted using style sheets but including them in the configuration when installing takes up too much space so I can't use them. Is it possible to remove the arrows by inheriting from QStyle or something?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该创建 QStyle 的子类(或像 QCommonStyle 这样的子类)并重新实现其 drawComplexControl() 函数以自行绘制 CC_ScrollBar 元素。
阅读 QStyle 的文档了解更多信息。
You should create a subclass of a QStyle (or some subclass like QCommonStyle) and reimplement its drawComplexControl() function to paint CC_ScrollBar element by yourself.
Read QStyle's documentation for more.
这可能是一个愚蠢的答案,但如果您只是在代码中将样式表本身指定为
setStyleSheet
的 QString 参数而不是为其维护一个单独的文件,会有帮助吗?This might be a dumb answer but would it help if you just specified the style sheet itself in code as a
QString
argument tosetStyleSheet
rather than maintain a separate file for it?您可以尝试更改滚动条的调色板设置(根据设计器滚动条箭头颜色是“按钮文本”颜色),但这种方法看起来有点小技巧......
更“重”的方法是继承滚动条小部件并重新实现绘制方法,但有些看起来有点矫枉过正...
所以,你必须选择 Little Hack 与 Overkill :)。虽然也许存在另一种解决方案
You can try to change palette settings for your scroll bar (according to designer scroll bar arrow color is "button text" color), but this approach looks lick little hack...
More "heavy" approach, is inherit from scroll bar widget and reimplement paint method, but there are it is looks like overkill...
So, you must choose little hack vs overkill :). Though maybe there are exist another solution