In my Qt 5.7.1 application I've some buttons, I want to align button's icons to left and centre text, but there is no option in designer to do this.
I can align icon and text left by adding to button stylesheet this code:
text-align:left;
But it's not what I want to achieve. So, could you please tell me, If there is any option to align icon to left, and keep text aligned center? Thank you for help.



Simply specialize
QPushButtonand overridepaintEventandsizeHint, as proposed by cbuchart here. Then use it as a regularQPushButton.MyButtondeclaration and implementation:mybutton.h:
mybutton.cpp:
Exemple of usage:
Here is an example where "Promote widget" feature in Qt Designer was used to create
MyButtonfrom .ui files:mainframe.ui:
mainwindow.h:
mainwindow.cpp:
main.cpp:
Results in:
QPushButton(usingQPushButton::setText), you don't need to keep a reference to a mockupQLabelto change button's text.