设置label中的对齐方式

QLabel.setAlignment (self, Qt.Alignment)

下面查看Qt.Alignment

Qt.AlignmentFlag

This enum type is used to describe alignment. It contains horizontal and vertical flags that can be combined to produce the required effect.

The TextElideMode enum can also be used in many situations to fine-tune the appearance of aligned text.

The horizontal flags are:

 

ConstantValueDescription
Qt.AlignLeft 0x0001 Aligns with the left edge.
Qt.AlignRight 0x0002 Aligns with the right edge.
Qt.AlignHCenter 0x0004 Centers horizontally in the available space.
Qt.AlignJustify 0x0008 Justifies the text in the available space.

The vertical flags are:

 

ConstantValueDescription
Qt.AlignTop 0x0020 Aligns with the top.
Qt.AlignBottom 0x0040 Aligns with the bottom.
Qt.AlignVCenter 0x0080 Centers vertically in the available space.

You can use only one of the horizontal flags at a time. There is one two-dimensional flag:

 

ConstantValueDescription
Qt.AlignCenter AlignVCenter | AlignHCenter Centers in both dimensions.

You can use at most one horizontal and one vertical flag at a time. Qt.AlignCenter counts as both horizontal and vertical.

Three enum values are useful in applications that can be run in right-to-left mode:

 

ConstantValueDescription
Qt.AlignAbsolute 0x0010 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.
Qt.AlignLeading AlignLeft Synonym for Qt.AlignLeft.
Qt.AlignTrailing AlignRight Synonym for Qt.AlignRight.

Masks:

 

ConstantValue
Qt.AlignHorizontal_Mask AlignLeft | AlignRight | AlignHCenter | AlignJustify | AlignAbsolute
Qt.AlignVertical_Mask AlignTop | AlignBottom | AlignVCenter

Conflicting combinations of flags have undefined meanings.

The Alignment type is a typedef for QFlags<AlignmentFlag>. It stores an OR combination of AlignmentFlag values.

 

简单示范:

self.label.setAlignment(Qt.AlignLeft)

posted @ 2016-07-27 23:55  进撃の大鸟  阅读(4835)  评论(0编辑  收藏  举报