Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. PushButton icon spacing
Forum Updated to NodeBB v4.3 + New Features

PushButton icon spacing

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 280 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    illufoxKasunagi
    wrote on last edited by
    #1

    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() +
                    ";"
                    "}");
    }
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved