user5435739
user5435739

Reputation: 83

PyQt4 QPushButton text and icon alignment

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

I tried to do the following:

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

but I got:

button picture

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

Upvotes: 2

Views: 14160

Answers (2)

K.Mulier
K.Mulier

Reputation: 9620

For some reason, setLayoutDirection() didn't work for me (PyQt5). I'm using the following option:

btn2.setStyleSheet("QPushButton { text-align: left; }")

This works pretty good. You can find more options for style sheets on this link: http://doc.qt.io/qt-5/stylesheet-reference.html

Upvotes: 6

Brendan Abel
Brendan Abel

Reputation: 37499

You can use 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.

Upvotes: 5

Related Questions