PDA

View Full Version : How to right-justify QLabel text



JimDaniel
30th January 2008, 00:19
Hi, this is what I'm getting:

1000
100
10
1

but this is what I want, sans the underlines:

1000
_100
__10
___1

How do I do this? Each of the numbers is a QLabel set at a fixed position.

I have tried many variations setting the alignment with Qt::AlignRight, Qt::AlignJustify, and setting the layout direction Qt::RightToLeft in the hopes that some combination would work, but it doesn't.

wysota
30th January 2008, 01:08
AlignRight should work. If it doesn't then it's probably because your labels are not aligned correctly relative to each other. Put them all into a single vertical layout.

jpn
30th January 2008, 08:55
See Qt::AlignAbsolute (http://doc.trolltech.com/4.3/qt.html#AlignmentFlag-enum):


If the widget's layout direction is Qt::RightToLeft (instead of Qt::LeftToRight, the default), Qt::AlignLeft refers to the right edge and Qt::AlignRight to the left edge. This is normally the desired behavior. If you want Qt::AlignLeft to always mean "left" and Qt::AlignRight to always mean "right", combine the flag with Qt::AlignAbsolute