Qt - QScrollBar 皮肤问题
我试图通过重新实现 paintEvent
函数来为 QScrollBar
换肤,但遇到了麻烦。我找不到有关滚动条上按钮的任何信息,并且只能找到有关实际滑块(您可以抓取和拖动的手柄)的(有限)信息。我也查看了 QStyle,它仍然只提供有关滚动手柄的信息,而不提供有关按钮的信息。硬编码或使用幻数不是一个选项,因为按钮在不同操作系统上的放置方式不同(请参阅:这里)。有没有什么方法可以以编程方式获取滚动条的布局,以便我可以准确地将按钮和滚动手柄渲染在正确的位置?
I'm trying to skin a QScrollBar
by reimplementing the paintEvent
function, but I'm having trouble. I can't find any information on the buttons on the scroll bar, and I can only find (limited) information on the actual slider (the handle you can grab and drag). I looked at the QStyle as well and it still only gives information on the scroll handle and not the buttons. Hardcoding or using magic numbers is not an option because the buttons are placed differently on different operating systems (see: Here). Is there any way to programmatically get the layout of the Scrollbar, so I could accurately render the buttons and scroll handle at their correct positions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于绘画本身是由底层样式完成的,而不是 QScrollBar 本身,我建议如下:
作为替代方案,我建议使用 Qt 样式表来更改 QScrollBar 的外观
As the painting itself is done by underlying style, not QScrollBar itself I'd suggest following:
As alternative I'd suggest using Qt Style Sheets to change QScrollBar look'n'feel