How can I place the icon after the text of a QPushButton in PyQt5?
The icon should not come before the text - it should come after or below the text.
Currently it's looking like this:
but it should be like this: Track ⨁
from PyQt5.QtWidgets import QApplication, QPushButton, QWidget, QVBoxLayout
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import Qt
import sys
app = QApplication(sys.argv)
window = QWidget()
layout = QVBoxLayout(window)
btn_add_track = QPushButton("Track")
btn_add_track.setIcon(QIcon("Icons/plus.png"))
layout.addWidget(btn_add_track)
window.show()
sys.exit(app.exec_())
The simplest option is to change the direction of the button layout:
btn_add_track.setLayoutDirection(Qt.LayoutDirection.RightToLeft)
Unlike the other solution, this will maintain the appearance of the original button such as centering the icon text and text relative to the button (this can also be done with the other solution but requires much more code)