Python QPushButton setIcon:将图标放在按钮上
我想将一个 ICON 放入按钮中。代码应该像这样工作:
self.printButton = QtGui.QPushButton(self.tab_name)
self.printButton.setIcon(QtGui.QPixmap('printer.tif'))
self.printButton.setGeometry(QtCore.QRect(1030, 500, 161, 61))
但是,它给出了错误消息:
TypeError: argument 1 of QAbstractButton.setIcon() has an invalid type
这里缺少什么?
高度赞赏所有意见和建议。
I want to put an in ICON into a push button.. the code should work like that:
self.printButton = QtGui.QPushButton(self.tab_name)
self.printButton.setIcon(QtGui.QPixmap('printer.tif'))
self.printButton.setGeometry(QtCore.QRect(1030, 500, 161, 61))
But instead, it gives the error message:
TypeError: argument 1 of QAbstractButton.setIcon() has an invalid type
What is missing here?
All comments and suggestions are highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这很奇怪,我很快在我的 C++ 应用程序上测试了代码,它似乎正在工作......
也许通过使用它你可以纠正你的问题:
希望这会有所帮助......
This is strange, I quickly tested the code on my C++ application and it seems to be working...
Maybe by using this you could correct your problem :
Hope this helps a bit...
创建一个 QIcon 而不是 QPixmap 来传递给 setIcon()。尝试将第二行更改为
Create a QIcon rather than a QPixmap for passing to setIcon(). Try changing the second line to
嗨,Baysmith 和 Andy...感谢您的投入。我测试了你的建议,它有效。我还必须添加setIconSize,否则图标显示很小。这是代码:
希望这对其他人也有帮助....|:0),
Hi Baysmith and Andy... thanks for the input. I tested your suggestions, it worked. I also have to add setIconSize, otherwise the icon is displayed very small. Here is code:
Hope this help others too....|:0),