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.
  • pauleddP Offline
    pauleddP Offline
    pauledd
    wrote on last edited by pauledd
    #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"

    raven-worxR 1 Reply Last reply
    0
    • pauleddP pauledd

      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"

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on 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
      • hskoglundH Online
        hskoglundH Online
        hskoglund
        wrote on last edited by hskoglund
        #3

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

        comboBoxTime->setLayoutDirection(Qt::RightToLeft);
        
        1 Reply Last reply
        0
        • pauleddP Offline
          pauleddP Offline
          pauledd
          wrote on last edited by pauledd
          #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...

          raven-worxR 1 Reply Last reply
          0
          • pauleddP Offline
            pauleddP Offline
            pauledd
            wrote on 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
            • pauleddP pauledd

              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...

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on 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

              pauleddP 1 Reply Last reply
              0
              • raven-worxR raven-worx

                @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.

                pauleddP Offline
                pauleddP Offline
                pauledd
                wrote on last edited by
                #7

                @raven-worx np, thanks anyway

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Swapnil_Shelke
                  wrote on 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