PyQt:我可以制作一个带有图标和文本的工具栏按钮吗?
我正在通过示例来学习 PyQt。在本例中,我正在使用位于 \Python26\Lib\site-packages\PyQt4\examples\activeqt\webbrowser
的 webbrowser 示例。
如果您添加一行来设置 QAction 的图标文本属性,该演示会做一些非常奇怪的事情。
这是我尝试过的更改的代码示例:
self.actionBack = QtGui.QAction(MainWindow)
self.actionBack.setIcon(QtGui.QIcon(":/icons/image1.xpm"))
self.actionBack.setObjectName("actionBack")
# added this line:
self.actionBack.setIconText("Back")
有一次我尝试过,整个工具栏变成了空白。我无法重现这一点,现在我对这一行的更改没有任何影响。
我想要弄清楚的是如何对 QAction 进行操作,以便工具栏在图像旁边的按钮上有文本,或者可以像这样完成吗?还有其他方法可以使工具栏包含一些文本和图标吗?
I am learning PyQt by playing with examples. In this case, I'm playing with the webbrowser example that is located at \Python26\Lib\site-packages\PyQt4\examples\activeqt\webbrowser
.
The demo does something really odd if you add one line to set the icon text property of a QAction.
Here's a code sample of the change I tried:
self.actionBack = QtGui.QAction(MainWindow)
self.actionBack.setIcon(QtGui.QIcon(":/icons/image1.xpm"))
self.actionBack.setObjectName("actionBack")
# added this line:
self.actionBack.setIconText("Back")
One time I tried it, and the entire toolbar went blank. I can't reproduce that, now I have no effect from that one line change.
What I'm trying to figure out is what to do to the QAction so that the toolbar has text on the button beside the image, or can it be done at all like this? Is there some other way to make the toolbar have some text plus an icon?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在要添加操作的工具栏上设置按钮样式:
Try setting the button style on the toolbar that the actions are being added to: