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. How To Style QPushButton Icon?
QtWS25 Last Chance

How To Style QPushButton Icon?

Scheduled Pinned Locked Moved General and Desktop
qt5.5qpushbuttoniconstylesheetstylepositionpositioning
8 Posts 2 Posters 10.9k 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.
  • M Offline
    M Offline
    maximo
    wrote on last edited by
    #1

    I see that we can set the icon property on a QPushButton. I can change the size of it. However, how do I reposition it slightly? Can I use a stylesheet to do that?

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

      Hi
      not sure the if the image-position works with icon but you could try
      http://doc.qt.io/qt-5/stylesheet-reference.html#image-prop

      M 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        not sure the if the image-position works with icon but you could try
        http://doc.qt.io/qt-5/stylesheet-reference.html#image-prop

        M Offline
        M Offline
        maximo
        wrote on last edited by
        #3

        @mrjj Tried that. I can set a background-image to point to my image resource URL, and then use background-position to position it, but it won't let me do anything except position names. It doesn't support pixel sizing like so:

        background-position:4px left;
        
        mrjjM 1 Reply Last reply
        0
        • M maximo

          @mrjj Tried that. I can set a background-image to point to my image resource URL, and then use background-position to position it, but it won't let me do anything except position names. It doesn't support pixel sizing like so:

          background-position:4px left;
          
          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @maximo
          Ok, I kinda feared it would not.

          M 1 Reply Last reply
          0
          • mrjjM mrjj

            @maximo
            Ok, I kinda feared it would not.

            M Offline
            M Offline
            maximo
            wrote on last edited by
            #5

            @mrjj The only fix I could come up with was creating some transparent background space around the icon image itself, and then moving the icon within that space. I then deleted the old resource image and re-imported the new one. Now my icons line up properly with the text on the right.

            mrjjM 1 Reply Last reply
            0
            • M maximo

              @mrjj The only fix I could come up with was creating some transparent background space around the icon image itself, and then moving the icon within that space. I then deleted the old resource image and re-imported the new one. Now my icons line up properly with the text on the right.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @maximo
              Well, its an ok work around I guess.

              M 1 Reply Last reply
              0
              • mrjjM mrjj

                @maximo
                Well, its an ok work around I guess.

                M Offline
                M Offline
                maximo
                wrote on last edited by
                #7

                @mrjj I guess it would be nice if the Qt developers would provide a stylesheet setting in Qt5.6 (coming soon, perhaps) that allows one to position that icon a little better.

                mrjjM 1 Reply Last reply
                0
                • M maximo

                  @mrjj I guess it would be nice if the Qt developers would provide a stylesheet setting in Qt5.6 (coming soon, perhaps) that allows one to position that icon a little better.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @maximo
                  Agree.
                  I wonder if there is something secret I missed in some Doc.

                  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