1

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.

Brendan Abel
  • 35,343
  • 14
  • 88
  • 118
user5435739
  • 73
  • 2
  • 2
  • 6

2 Answers2

5

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.

Brendan Abel
  • 35,343
  • 14
  • 88
  • 118
5

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

K.Mulier
  • 8,069
  • 15
  • 79
  • 141