1

I have a QToolButton. I wanted text and icon to be on it. I set button style by setToolButtonStyle(Qt::ToolButtonTextBesideIcon).

But icon and text are so close to each other. Is there a method to give some space between icon and text by css?

mehmetfa
  • 199
  • 3
  • 15
  • Maybe try use `Padding`: http://www.w3schools.com/css/css_padding.asp in css ? I think you should `add padding-top: value px;` – Szymson May 30 '16 at 13:10
  • You can make the icons wider, since they can be png with transparency. If you make them all same-width, they even align nicely vertically. – elsamuko Feb 05 '20 at 06:44

2 Answers2

0

You can't. There is no such a property neither for QToolButton (nor for QPushButton). All the properties for these buttons are in the documentation.

One thing you can do is to create your own class inheriting from QToolButton and overriding the paintEvent(). In this function, you will manually place your icon.

This is the shortest solution, but if you're brave enough, there are longer paths, like creating your own button subclassing directly QWidget (but in this case, you will need to implement ALL its behavior).

IAmInPLS
  • 4,051
  • 4
  • 24
  • 57
  • 1
    Thanks a lot. I just made the text starting with a little space. I mean, I changed the text "something" to " something". This solved my problem for now. I hope I will not have to create/override something. :) – mehmetfa May 30 '16 at 13:48
  • Be careful with that though, if you have several buttons, you will have to write blank spaces on every buttons ^^ – IAmInPLS May 30 '16 at 13:49
  • Thanks again. I wrote a simple function for that. – mehmetfa May 30 '16 at 13:53
  • You can also write a subclass for `QToolButton` overriding its `setText` method to append the leading spaces. – MarSoft May 10 '21 at 22:13
0

You can achieve it although this is not the documented solution. Just provide spaces in QPushButton text start. By Doing this, icon and text will automatically go far from each other.

Rohit
  • 1
  • 1