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. Adding gap between QIcon and text in a QPushButton
Forum Updated to NodeBB v4.3 + New Features

Adding gap between QIcon and text in a QPushButton

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 2.1k Views
  • 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.
  • S Offline
    S Offline
    shreya_agrawal
    wrote on last edited by shreya_agrawal
    #1

    I have a QPushButton, in which I am adding a QIcon and some text. How can I add space between the icon and the text without using a spacer or changing the size of the icon. I tried adding padding, but it isn't giving me desired results.
    I also considered adding the icon and the text inside two different labels and then adding those two labels in a QHBoxLayout and adding spacing in it and then finally setting this layout as the button layout, but this would be a complex solution. Is there a better way of doing this?

    JonBJ 1 Reply Last reply
    0
    • S shreya_agrawal

      I have a QPushButton, in which I am adding a QIcon and some text. How can I add space between the icon and the text without using a spacer or changing the size of the icon. I tried adding padding, but it isn't giving me desired results.
      I also considered adding the icon and the text inside two different labels and then adding those two labels in a QHBoxLayout and adding spacing in it and then finally setting this layout as the button layout, but this would be a complex solution. Is there a better way of doing this?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @shreya_agrawal
      Padding is inside whatever widget, likely to either change its size or that of its content. I don't know whether it would work, but did you try margin instead, which is outside of widget?

      S 1 Reply Last reply
      0
      • JonBJ JonB

        @shreya_agrawal
        Padding is inside whatever widget, likely to either change its size or that of its content. I don't know whether it would work, but did you try margin instead, which is outside of widget?

        S Offline
        S Offline
        shreya_agrawal
        wrote on last edited by
        #3

        @JonB
        Thank you for your reply!
        Then, we will have to give margin to the icon, since we need space between the icon and the text, but margin can't be directly given to a QIcon.

        JonBJ 1 Reply Last reply
        0
        • S shreya_agrawal

          @JonB
          Thank you for your reply!
          Then, we will have to give margin to the icon, since we need space between the icon and the text, but margin can't be directly given to a QIcon.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @shreya_agrawal
          I think you are right, I did not look into it, I thought one could set margin on the icon, but not.

          https://stackoverflow.com/questions/17345648/how-to-change-qpushbutton-icon-text-spacing-with-stylesheets confirms how difficult it is, but offers a number of possibilities. From doing the paint yourself to putting a space at start of text.

          S 1 Reply Last reply
          1
          • JonBJ JonB

            @shreya_agrawal
            I think you are right, I did not look into it, I thought one could set margin on the icon, but not.

            https://stackoverflow.com/questions/17345648/how-to-change-qpushbutton-icon-text-spacing-with-stylesheets confirms how difficult it is, but offers a number of possibilities. From doing the paint yourself to putting a space at start of text.

            S Offline
            S Offline
            shreya_agrawal
            wrote on last edited by
            #5

            @JonB
            Yes, both approaches do work. I think I will I will just put blank space at start of the text to avoid unnecessary complexity.

            1 Reply Last reply
            1
            • S shreya_agrawal has marked this topic as solved on

            • Login

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