View Full Version : How to right-justify the text inside a QComboBox

24th September 2014, 01:35
I have a QComboBox with different texts. I want to display only the most right characters of the texts since each text represent a long file name.

How to right justify my texts in the QComboBox?

24th September 2014, 04:38
You could try using the QComboBox::setItemData() method with the Qt::TextAlignmentRole and a value of Qt::AlignRight | Qt::AlignVCenter. I do not know if the combo box will obey this, but it is worth a try.

You could also create a left-elided string using QFontMetrics::elidedText() if you know the width of the text field in the combo box.

Henry Blue Heeler
24th September 2014, 06:50
Checkout Bookmarc's solution: