PushButton icon spacing
Unsolved
QML and Qt Quick
-
Hi Experts! i have a trouble to set spacing between icon and text in QPushButton. I tried to edit the styling with
qproperty-iconSpacing
, but it doesn't work. Here's the example of my code :#include "buttonSidebarActive.h" #include "../resources/iconPaths.h" #include "../styles/colors.h" #include "../styles/textStyle.h" #include <qboxlayout.h> #include <qstyle.h> ButtonSidebarActive::ButtonSidebarActive(const QString &iconType, const QString &buttonLabel, QWidget *parent) : QPushButton(buttonLabel, parent) { QBoxLayout *layout = new QBoxLayout(QBoxLayout::LeftToRight, this); QString iconPath = IconPaths::getIconPath(iconType); setIcon(QIcon(iconPath)); setIconSize(QSize(40, 40)); setStyleSheet("QPushButton {" " padding: 12px 8px;" " text-align: left;" " border: 0 solid;" " border-radius: 12px;" " background-color:" + Colors::Secondary500.name() + ";" " color: " + Colors::StandardWhite.name() + ";" " " + TextStyle::BodyBigBold() + "}" "QPushButton:hover {" " background-color: " + Colors::Secondary300.name() + ";" "}" "QPushButton:pressed {" " background-color: " + Colors::Primary600.name() + ";" "}" "QPushButton:disabled {" " border-color: " + Colors::Grey400.name() + ";" " color: " + Colors::Grey400.name() + ";" "}"); }
-
Hi and welcome to devnet,
AFAIK, you can't do it like that.
If you want that distance to be different, you will have to implement that yourself.
One way is to customize the size handling and paint event.
The other is to create an image with a transparent background which provides the extra gap you are after.