从 QStyle 更改 Widget 的大小
我正在写一个 QStyle
这里我将 QProgressBar 更改为 Slim 单行,没有文本。所以高度也会减少到5px。然而,小部件宽度将由布局决定。我应该在“我的样式”的 drawControl
中做什么来更改小部件高度?
I am writting a QStyle
Here I am changing the QProgressBar to a Slim single line, no text. So Height will also be reduced to 5px. However Widget Width will be determined by layout. what should I do in My Style's drawControl
to change widget height ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从未真正编写过
QStyle
,但如果您要调整drawControl
内的任何内容的大小,我会认为很奇怪。通过快速查看文档,我可能会错,似乎建议您覆盖 subElementRect 并根据当前宽度和您的首选高度返回一个矩形。我假设这将由布局活动调用,并在调用drawControl
时进行排序。I've never actually written a
QStyle
but I would consider it odd if you were supposed to resize anything insidedrawControl
. I could be wrong on this by a quick review of the documentation would seem to suggest that you would override subElementRect and return a rect based on current width and your preferred height. I assume this would be called by layout activities and would be sorted out by the timedrawControl
gets called.您需要固定小部件的高度吗?或者只是绘制的高度永远不会超过 5 像素?首先,在抛光函数上设置高度和调整大小策略。对于第二个,覆盖 QStyle 中的绘图以仅使用 5 个像素。进行绘图的函数通常采用矩形;如果您正确地覆盖了适当的函数,您可以使用修改后的矩形来调用基类的绘制。不幸的是,我已经很多年没有做过任何 QStyle 工作了,所以我不确定这些功能到底是什么。
Do you need the height for the widget to be fixed? Or just the drawn height to never go past 5 pixels? For the first, set the height and resize policy on the polish function. For the second, override the drawing in the QStyle to only use 5 pixels. The functions that do the drawing generally take rects; you can call the base class's draw with a modified rect if you properly override the appropriate functions. Unfortunately, it's been years since I've done any QStyle work, so I'm not sure exactly what those functions are.