Search code examples
htmlcssqtqtextdocument

Adding space between image and text in QPushButton


I have a rich text button, which is a descendant of QPushButton and uses QTextDocument for limited HTML support. I need to create a button, which has an icon on the left and a caption on the right (with some space between image and text).

So, let's assume that we have set_html(const QString& html) method. I failed to add the space between image and text via style attribute (with margin) in img tag. What will be the input string for that method?


Solution

  • You can try the following verbose workaround (due to limited HTML support in QLabel):

    <table><tr><td><img src=":/save_monitor_settings.png"/></td><td style="padding-left:10px;">Some text</td></tr></table>