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. why the text of the qpushbutton could not be set text-align:center?
Forum Update on Monday, May 27th 2025

why the text of the qpushbutton could not be set text-align:center?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 2.6k 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.
  • nicker playerN Offline
    nicker playerN Offline
    nicker player
    wrote on last edited by
    #1

    I added a pushbutton menu on the push button.and set the style like this.

    QPushButton{ text-align:center;}
    QPushButton::menu-indicator{ image:none;}
    

    even though I couldnt see the menu-indicator, the text of the pushbutton still is on the left side.I dont know why.Is it related to the

            subcontrol-origin:margin;
    	subcontrol-position:bottom right;
    	margin-top:5px;
    

    something else?

    Axel SpoerlA 1 Reply Last reply
    0
    • nicker playerN nicker player

      I added a pushbutton menu on the push button.and set the style like this.

      QPushButton{ text-align:center;}
      QPushButton::menu-indicator{ image:none;}
      

      even though I couldnt see the menu-indicator, the text of the pushbutton still is on the left side.I dont know why.Is it related to the

              subcontrol-origin:margin;
      	subcontrol-position:bottom right;
      	margin-top:5px;
      

      something else?

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      @nicker-player
      Unfortunately, the text alignment of a QPushButtonisn't implemented (yet).

      Software Engineer
      The Qt Company, Oslo

      JonBJ nicker playerN 2 Replies Last reply
      0
      • Axel SpoerlA Axel Spoerl

        @nicker-player
        Unfortunately, the text alignment of a QPushButtonisn't implemented (yet).

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

        @Axel-Spoerl
        Interesting. Per https://doc.qt.io/archives/qt-4.8/stylesheet-reference.html#text-align-prop it claims to have been supported for a QPushButton since at least Qt 4.8, so I wonder when "yet" will be... ;-)

        Axel SpoerlA 1 Reply Last reply
        0
        • JonBJ JonB

          @Axel-Spoerl
          Interesting. Per https://doc.qt.io/archives/qt-4.8/stylesheet-reference.html#text-align-prop it claims to have been supported for a QPushButton since at least Qt 4.8, so I wonder when "yet" will be... ;-)

          Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #4

          @JonB
          I actually wanted to fix this a while ago, and even started writing a patch. But I got stuck in complexity and moved on to other tasks in the absence of a strong use case…

          Software Engineer
          The Qt Company, Oslo

          JonBJ 1 Reply Last reply
          1
          • Axel SpoerlA Axel Spoerl

            @JonB
            I actually wanted to fix this a while ago, and even started writing a patch. But I got stuck in complexity and moved on to other tasks in the absence of a strong use case…

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

            @Axel-Spoerl :)

            1 Reply Last reply
            0
            • Axel SpoerlA Axel Spoerl

              @nicker-player
              Unfortunately, the text alignment of a QPushButtonisn't implemented (yet).

              nicker playerN Offline
              nicker playerN Offline
              nicker player
              wrote on last edited by
              #6

              @Axel-Spoerl
              So how could I put the text on the center position of the pushbutton object.With using the setFont method?

              C JonBJ 2 Replies Last reply
              0
              • nicker playerN nicker player

                @Axel-Spoerl
                So how could I put the text on the center position of the pushbutton object.With using the setFont method?

                C Offline
                C Offline
                ChrisW67
                wrote on last edited by
                #7

                The default behaviour of QPushbutton is to centre the text.

                Does the presence of a menu indicator force left alignment?

                Why you would want to make a menu pushbutton and then hide any indication that a menu is present is a bit too "modern UI" for me.

                1 Reply Last reply
                0
                • nicker playerN nicker player

                  @Axel-Spoerl
                  So how could I put the text on the center position of the pushbutton object.With using the setFont method?

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

                  @nicker-player
                  As @ChrisW67 says, since the default of QPushButton is to center text it is not clear what your issue is exactly. Do you require adjustment by stylesheet? If not you can control the placement or hide the menu indicator more directly via code?

                  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