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. QComboBox align text stylesheet?
QtWS25 Last Chance

QComboBox align text stylesheet?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qcomboboxaligntextalignmentstylesheet
8 Posts 4 Posters 12.3k 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.
  • P Offline
    P Offline
    pauledd
    wrote on 5 Sept 2016, 08:01 last edited by pauledd 9 May 2016, 08:02
    #1

    Hi there,
    Is it possible to align the text in a QComboBox without setting it to setEditable true? I read someone suggesting stylesheets but I was not able to find any sample code.
    I want to align this text in the box to the right side:

    QComboBox Image

    comboBoxTime->setStyleSheet("align:right;") only gives "Unknown property align"

    R 1 Reply Last reply 5 Sept 2016, 08:38
    0
    • P pauledd
      5 Sept 2016, 08:01

      Hi there,
      Is it possible to align the text in a QComboBox without setting it to setEditable true? I read someone suggesting stylesheets but I was not able to find any sample code.
      I want to align this text in the box to the right side:

      QComboBox Image

      comboBoxTime->setStyleSheet("align:right;") only gives "Unknown property align"

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 5 Sept 2016, 08:38 last edited by
      #2

      @pauledd
      not the QStyle code doesn't consider text alignment.
      It determines the alignment itself, just by the QComboBox's layout direction property. But this won't be the result you desire.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • H Offline
        H Offline
        hskoglund
        wrote on 5 Sept 2016, 08:38 last edited by hskoglund 9 May 2016, 08:41
        #3

        One workaround (pretend that you're in the Middle East :-):

        comboBoxTime->setLayoutDirection(Qt::RightToLeft);
        
        1 Reply Last reply
        0
        • P Offline
          P Offline
          pauledd
          wrote on 5 Sept 2016, 08:58 last edited by pauledd 9 May 2016, 08:59
          #4

          Thank you, I tried that but it still looks so squashed to the border and it also moves the arrow to the left what makes it looking even more odd,

          image

          maybe that has something to do with margins... I will play more around with spacing...

          R 1 Reply Last reply 5 Sept 2016, 09:07
          0
          • P Offline
            P Offline
            pauledd
            wrote on 5 Sept 2016, 09:04 last edited by
            #5

            I found a simple solution, I just added two whitespaces before the text, of cause I needet to change that text in the rest of the code too, but it looks now as I desired:
            image

            1 Reply Last reply
            0
            • P pauledd
              5 Sept 2016, 08:58

              Thank you, I tried that but it still looks so squashed to the border and it also moves the arrow to the left what makes it looking even more odd,

              image

              maybe that has something to do with margins... I will play more around with spacing...

              R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 5 Sept 2016, 09:07 last edited by
              #6

              @pauledd said in QComboBox align text stylesheet?:

              Thank you, I tried that but it still looks so squashed to the border and it also moves the arrow to the left what makes it looking even more odd,

              image

              maybe that has something to do with margins... I will play more around with spacing...

              thats why i said the result wont be what you desire.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              P 1 Reply Last reply 5 Sept 2016, 09:29
              0
              • R raven-worx
                5 Sept 2016, 09:07

                @pauledd said in QComboBox align text stylesheet?:

                Thank you, I tried that but it still looks so squashed to the border and it also moves the arrow to the left what makes it looking even more odd,

                image

                maybe that has something to do with margins... I will play more around with spacing...

                thats why i said the result wont be what you desire.

                P Offline
                P Offline
                pauledd
                wrote on 5 Sept 2016, 09:29 last edited by
                #7

                @raven-worx np, thanks anyway

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Swapnil_Shelke
                  wrote on 31 Mar 2017, 05:01 last edited by
                  #8

                  QComboBox {background-color:rgb(190,190,190);color:black;padding-left: 10px;padding-right: 30px;border-style: solid;border-width: 0px;}

                  "padding-left: 10px;"

                  the padding will shift the combo-box displayed content form the left edge

                           QComboBox::drop-down {subcontrol-origin: padding;  subcontrol-position: top right;width: 40px;border: 0px ;}
                  

                  "subcontrol-position: top right;"

                  and the above will position wot text to the right.

                  Hopefully this helps.

                  1 Reply Last reply
                  1

                  • Login

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