Search code examples
qt5qt-designerpyside2

Add Spacing in QPushButton Text


I've been searching around to find a way to implement spacing on QPushButton text. I've managed to style its alignment but can't find any clue on how to create spacing between letters. I'm using pyside2 and Qt Designer to draw my window. I saw around StackOverflow questions regarding spacing between icon and text; that's not what I was looking for. If not possible, I accept any alternative to get around this problem. Thanks


Solution

  • While QSS is based on CSS2.1, which provides the letter-spacing property, it's not supported for widgets.

    The property editor of Designer also doesn't support it, so the only solution is to do it by code, using setLetterSpacing():

    font = button.font()
    font.setLetterSpacing(font.AbsoluteSpacing, 4)
    button.setFont(font)