PyQt4 QPushButton 文本和图标对齐 [英] PyQt4 QPushButton text and icon alignment

查看:79
本文介绍了PyQt4 QPushButton 文本和图标对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个带有文本和图标的按钮,例如 Next =>,我正在使用 QPushButton.

I want to create a button with text and icon, for example Next =>, and I'm using QPushButton.

我尝试执行以下操作:

btn2 = QtGui.QPushButton('Next',self)
btn2.setIcon(QIcon(QPixmap("next.png")))

但我得到了:

我希望箭头(图标)出现在文本的右侧(下一步")或下方.请帮忙.

I want the arrow (icon) to appear on the right side of the text ("Next"), or below. Please help.

推荐答案

您可以使用 setLayoutDirection()

btn2.setLayoutDirection(QtCore.Qt.RightToLeft)

有时看起来有点奇怪,您必须调整按钮大小和边距才能使其看起来正确.

It can sometimes look a little weird, and you'll have to play with the button size and margins to get it to look right.

这篇关于PyQt4 QPushButton 文本和图标对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆