Qt::如何降低 QSpinBox 中的文本

发布于 2024-08-21 14:55:25 字数 168 浏览 4 评论 0原文

我正在使用带有自定义字体的旋转框,该字体在旋转框中看起来太高了。如何将文本移低?

我已经重新实现了 QStyle 并在另一个小部件中降低了字体,但我找不到在哪里使用旋转框来执行此操作。一定有一个 QRect 某个地方,您可以在其中移动它的顶部,但我不知道并且似乎无法找到它在哪里。

I'm using a spinbox with a custom font which looks too high in the spinbox. How do I move the text lower?

I have already reimplemented QStyle and made the font lower in another widget but I can't find where to do it with the spinbox. There must be a QRect somewhere where you can just move the top of it but I don't know and can't seem to find where it is.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苍风燃霜 2024-08-28 14:55:25

Qt specifies a QStyle::SC_SpinBoxEditField, which appears to be what you want to modify. If I recall correctly from a few years ago when I was doing stuff with styles, you should be able to hook into getting options for that subcontrol, which would include the rect within which it is supposed to be drawn. Modifying that might get the result you want. If not, it is a place to begin searching for your answer.

尹雨沫 2024-08-28 14:55:25

这更多的是猜测而不是肯定的答案,但您也许可以使用样式表来做到这一点:

spinbox->setStyleSheet("QSpinBox { bottom: -2px;}");

理想情况下会有一个子控件或仅用于文本的东西,但 样式表文档没有列出,这可能意味着上述内容会产生不良后果。

This is more of a guess than a positive answer, but you might be able to do this with stylesheets:

spinbox->setStyleSheet("QSpinBox { bottom: -2px;}");

Ideally there would be a subcontrol or something for just the text, but the stylesheet documentation doesn't list one, which might imply the above will have undesirable consequences.

时光无声 2024-08-28 14:55:25

你可以这样做:

spinBox->setAlignment(Qt::AlignCenter);//Or the Align Flag that you want

我希望这有帮助。

You can do:

spinBox->setAlignment(Qt::AlignCenter);//Or the Align Flag that you want

I hope this help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文