I want to learn how to automatically provide enough |
operators between each of the indexes from this a list. I understand that I cannot do '|'.join(a)
since the contents arent strings.
from PyQt6.QtWidgets import QApplication, QLabel, QMainWindow
from PyQt6.QtCore import Qt
import sys
class NewLabel(QLabel):
def __init__(
self,
place,
center=False,
left=False,
right=False,
top=False,
bottom=False,
**kwargs,
):
super().__init__(place, **kwargs)
cycle = (center, 0x0080), (center, 0x0004), (left, 0x0001), (right, 0x0002), (top, 0x0020), (bottom, 0x0040)
a = [Qt.AlignmentFlag(x[1]) for x in cycle if x[0]] or [Qt.AlignmentFlag(0x0001)]
self.setAlignment(a[0]|a[1]|a[2] if len(a) > 2 else a[0]|a[1] if len(a) > 1 else a[0]) # <-- how can I improve this row
class Main(QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.label = NewLabel(self, text='some string', center=True, right=True)
[x.resize(200,100) for x in (self, self.label)]
self.show()
if '__main__' in __name__:
app = QApplication(sys.argv)
window = Main()
app.exec()