Adding gap between QIcon and text in a QPushButton
-
I have a QPushButton, in which I am adding a QIcon and some text. How can I add space between the icon and the text without using a spacer or changing the size of the icon. I tried adding padding, but it isn't giving me desired results.
I also considered adding the icon and the text inside two different labels and then adding those two labels in a QHBoxLayout and adding spacing in it and then finally setting this layout as the button layout, but this would be a complex solution. Is there a better way of doing this? -
@shreya_agrawal
Padding is inside whatever widget, likely to either change its size or that of its content. I don't know whether it would work, but did you try margin instead, which is outside of widget? -
@shreya_agrawal
I think you are right, I did not look into it, I thought one could set margin on the icon, but not.https://stackoverflow.com/questions/17345648/how-to-change-qpushbutton-icon-text-spacing-with-stylesheets confirms how difficult it is, but offers a number of possibilities. From doing the paint yourself to putting a space at start of text.
-