Qt - 在应用程序中显示图形
我有一个在 Qt 中运行的应用程序,我本质上是在尝试重新设计它。我获得了用于背景、按钮等的图形。项目中没有当前图形。它没有背景,只是使用 QPushButtons 的默认外观。我使用 Qt 的 UI 设计编辑器,因为它不允许我在编辑器之外修改 mainwindow.ui 文件。
因此,我能够通过将样式表应用于 MainWindow 对象来设置应用程序的背景。 background-image:url("/path/to/bg.png")
就成功了。凉爽的。但现在应用程序中的所有 QLabel 都具有完全相同的背景。看起来 QWidget 的所有成员都继承了其父级的样式表信息。我该如何阻止呢?
我遇到的另一件事是我需要在应用程序的随机位置显示图形。我成功完成此操作的唯一方法是添加另一个 QWidget 并将样式表设置为它。这是一个正确的方法吗?显示非交互式图像的最佳方式是什么?
谢谢
I have an application running in Qt that I am essentially trying to re-skin. I was provided graphics to use for the background, buttons, etc. There are no current graphics in the project. It does not have a background and is just using the default look for QPushButtons. I am using Qt's UI Design editor because it will not let me just modify the mainwindow.ui file outside of the editor.
So I was able to set the background of the application by applying a stylesheet to the MainWindow object. background-image:url("/path/to/bg.png")
and that worked. Cool. But now all of the QLabels in the application have the exact same background. It seems that all of the members of a QWidget inherit the stylesheet information of their parent. How do I stop that?
The other thing I am experiencing is that I need to display graphics in random places on the application. The only way I have successfully done this is by adding another QWidget and setting the stylesheet to that. Is that a proper method? What is the best way to display a non-interactive image?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将样式表添加到 QApplication 并具体说明您想要设置样式的 QWidget。
这就是您要寻找的内容:
Add the stylesheet to the QApplication and be specific about what QWidgets you want to style.
Here's what you're looking for: