I have a QLabel with an unknown text that must be right-to-left, no matter which language is it. So I wrote this code:
def add_label(self):
text = self.text_input.text() # self.text_input is a QLineEdit
widget = QLabel(text)
widget.setAlignment(Qt.AlignRight)
widget.setStyleSheet("color: #000000")
self.layout.addWidget(widget) # self.layout is a QVBoxLayout
# I can't setAlignment for self.layout because there is some other QLabels in there that have a LtR alignment.
The problem in here is when I write a Persian text in self.text_input
and run the add_label
function (via pressing a button) it will automatically change the alignment to RtL and when I call the widget.setAlignment(Qt.AlignRight)
It will change back to LtR. But I want it to be RtL no matter which language is it.
How to fix this problem?