1

I am unable to combine two alignment flags as per Qt.Alignment documentation which reads: "You can use at most one horizontal and one vertical flag at a time. counts as both horizontal and vertical." <https://doc.qt.io/qtforpython-5/PySide2/QtCore/Qt.html%5C>

This this code snippet should work for a QLabel being added to QGridLayout to align the text vertically in the center of the label, and on the right edge.

        field_label = QLabel(fld_player[e] + ':  ')
        field_label.setAlignment(QtCore.Qt.AlignVCenter)
        field_label.setAlignment(QtCore.Qt.AlignRight)
        self.data_layout.addWidget(field_label, grid_row, grid_col)

However, the last 'setAlignment' statement becomes the dominant one. At issue is how to make both active.

Thinking order of statement significant, changing the order of execution results in the last 'setAlignment' statement becoming the dominant one.

Reasoning the two alignment flags were single bits in a word (right = 2, vcenter = 128, added = 130 of \b10000010) I have tried adding ('+') the two flags producing a type(int) and a TypeError; 'and'ing is tried with the first in the pair being dominant (not the commutative law).

I am out of ideas.

Art
  • 11
  • 2
  • Read about [bitwise operations](https://en.wikipedia.org/wiki/Bitwise_operation) and how they usually [work in C](https://en.wikipedia.org/wiki/Bitwise_operations_in_C) as in most other languages, [Python included](https://wiki.python.org/moin/BitwiseOperators). – musicamante Apr 29 '23 at 22:02

1 Answers1

0

Use the bitwise OR operator |

I modified your example like this

field_label = QLabel(fld_player[e] + ':  ')
field_label.setAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight)
self.data_layout.addWidget(field_label, grid_row, grid_col)
Saxtheowl
  • 4,136
  • 5
  • 23
  • 32