带阴影的 Qt 文本
我在其他应用程序中看到了这一点,即使外观非常轻微,效果却是高对比度 ->更好的可读性。
例如,Qt Designer 中左侧的选项卡或 Adobe Photoshop 中顶部的选项卡:文本有某种阴影,文本周围只有 1 个像素具有对比色。
有没有一种简单的方法可以用 Qt 来做到这一点?或者更复杂的?
谢谢。
I see this in other applications, even though the appearance is ever so slightly, the effect is a much high contrast -> better readability.
The tabs on the left in Qt Designer for example, or the tabs at the top in Adobe Photoshop: the text has some sort of shadow, only ever 1 pixel surrounding the text with a contrasting colour.
Is there a simple way to do this with Qt? Or a more complex one?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许
QGraphicsDropShadowEffect
?Maybe
QGraphicsDropShadowEffect
?有几种方法可以实现这种效果,但从概念上讲,您需要将其视为具有轻微偏移的两个文本层。
我之前通过重新实现 QWidget 的 PaintEvent() 方法并自己绘制文本层来完成此操作。或者您可以重新实现自定义 QStyle 的 drawItemText() 方法。但基本上就是这样完成的。
There are a couple ways of achieving this effect, but conceptually you need to look at it as being two text layers with a slight offset.
I have done this before by re-implementing the paintEvent() method of a QWidget and drawing the text layers myself. Or you can reimplement the drawItemText() method of a custom QStyle. But basically that is how it is done.
这是我用 Qt5 在所有按钮上制作文本阴影的方法。我不确定 Qt4 是否可以做到这一点。
...main() 中的某处
如果删除 QAbstractButtondynamic_cast,菜单标题也会被遮挡,这并不总是可取的。
Here is the way I did text shadow on all buttons with Qt5. I am not sure if this is possible with Qt4.
...somewhere in main()
If you remove the QAbstractButton dynamic_cast the menu titles will also be shadowed which is not always desirable.