QComboBox align text stylesheet?



  • 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"


  • Moderators

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



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

    comboBoxTime->setLayoutDirection(Qt::RightToLeft);
    


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



  • 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


  • Moderators

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



  • @raven-worx np, thanks anyway



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



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.