简体   繁体   中英

pyqt5 write right to left qlineedit

How to achieve writing from right to left in qlineedit? I want something like this:

在此处输入图像描述

Short answer:

self.input_field = QLineEdit()
self.input_field.setAlignment(QtCore.Qt.AlignRight)  # this is what you need!

Full code:

# import libraries you need!
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QLineEdit
from PyQt5 import QtCore


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        # some code

        self.input_field = QLineEdit()
        self.input_field.setAlignment(QtCore.Qt.AlignRight)  # this is what you need!

        # some code

        container = QWidget()
        self.setCentralWidget(container)


app = QApplication(sys.argv)

window = MainWindow()
window.show()

app.exec()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM