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. [Solved] QPushButtons with both text & icons
QtWS25 Last Chance

[Solved] QPushButtons with both text & icons

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 6.0k 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.
  • E Offline
    E Offline
    Endless
    wrote on last edited by
    #1

    I have a Designer UI Form that has about twenty QPushButtons. Each one of the buttons contains a unique icon as well as some text. The icons are all the same size, but the text is different for each button; as a result, the icons are at different positions in the QPushButton.

    To fix this, I added a number of leading spaces to each text string to get the icons to be in the same position in the QPushButton. That works fine, but now my application is being translated into other languages. Obviously the size of the text string is going to change, and I'll be back to the original problem of having icons be in a different position in each QPushButton. How can I retain the equal spacing?

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi there,
      Maybe put a picture with it, how are the buttons organized? How are the arranged? Where do you want the icon to appear and where the text?
      It might be an idea to use the grid layout for al the buttons and have them all stretched? When the layout changes size, so will all the buttons.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Endless
        wrote on last edited by
        #3

        There are 3 columns of 8, 3 and 5 buttons respectively. Each button has a width of 254 and a height of 50. By default, if you put an icon and text in a QPushButton, the icon shows up to the left of the text.

        This on an embedded Linux system where the application is running fullscreen, so the screen will never be resized.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jys0224
          wrote on last edited by
          #4

          how about subclassing QPushButton to implement your own drawing ?
          override paintEvent() to draw your icon and text at any position you want.
          text's full width/height can be acquired by using QFontMetrics.
          and icon size could be found by QPushButton's iconSize() as you know.

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

            Could you not use some CSS to manage the styling of the buttons? I have done something similar with Qtoolbuttons

            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