Answer the question
In order to leave comments, you need to log in
How to properly implement a button with an icon in QT?
Unfortunately, icons that are set via background or via icon in the button's properties cannot be set to offset in pixels. For background-position it is center, left, right and so on, but through the properties of QAbstactButton this is not the case either.
From here the question is: how can you still do it beautifully, without crutches and dancing with a tambourine? So that I can place the icon to the left of the button text at the distance I need?
Tried through QLabel, but then it will not be considered a click on the button when clicking on the icon, it would be possible to do it through a crutch, hang up a QLabel on a click, but this is a perversion, because there is not even such an event initially. Since I came from Delphi, I know that there is a HitTest property that was responsible for tracking mouse events. Is there such a thing here?
I would be grateful if you still tell me how to do it beautifully.
PS I know that you can make the picture wider (just add a void on the right), but I don't like this approach.
Answer the question
In order to leave comments, you need to log in
Set the attribute in QLabel
setAttribute(Qt::WA_TransparentForMouseEvents, true);
And it will click on the icon.
It will turn out beautifully only on QML or draw your own button.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question