Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PushButton spacing with Icon

PushButton spacing with Icon

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 1.1k Views 1 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.
  • HrishiGoblerH Offline
    HrishiGoblerH Offline
    HrishiGobler
    wrote on last edited by
    #1

    Hello experts,

    I am trying to add a pushbutton with a iCon inside that changes on click ( Basically a toggle button behavior.).
    I prefer to make the icon taking the complete space of the button, so that it looks like a real switch-button. However some spacing appears in the button (after the icon's boundary) making it look ugly. How can I avoid this spacing of the button .

    Thanks in advance,
    A new-bee of QT

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How are you doing it currently ?
      How does it show ?
      What version of Qt are you using ?
      On what OS ?

      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
      • HrishiGoblerH Offline
        HrishiGoblerH Offline
        HrishiGobler
        wrote on last edited by
        #3

        Thanks for your reply.

        • Currently I am doing similar to below code
          QPixmap pixmap("...x.jpg");
          QIcon ButtonIcon(pixmap);
          button->setIcon(ButtonIcon);
          button->setIconSize(pixmap.rect().size());
        • It shows the icon however, there are spacing appears in button's boundary ( i.e 3/4 pixels after the icon)
        • I am using QT 5.9
        • OS: Windows
        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @HrishiGobler said in PushButton spacing with Icon:

          i.e 3/4 pixels after the icon)

          Please be more precise what you mean here - QPushButton draw a border around the icon + some text. If you don't need text you can maybe also go with a QToolButton

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • HrishiGoblerH Offline
            HrishiGoblerH Offline
            HrishiGobler
            wrote on last edited by
            #5

            "QPushButton draw a border around the icon + some text." => Exactly this border is what I mean. Is there any way to avoid this border? I want the icon to completely fit the button without any border

            B 1 Reply Last reply
            0
            • HrishiGoblerH HrishiGobler

              "QPushButton draw a border around the icon + some text." => Exactly this border is what I mean. Is there any way to avoid this border? I want the icon to completely fit the button without any border

              B Offline
              B Offline
              Bonnie
              wrote on last edited by Bonnie
              #6

              @HrishiGobler set style sheet to it

              setStyleSheet("border: none;");
              

              But it may affect some other styled appearance.

              1 Reply Last reply
              2

              • Login

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