简体   繁体   English

如何让我的 QLabel 随书面文字滚动

[英]How can I make my QLabel scroll with the written text

Im making a calculator with pyqt5 but when the calculator QLabel overflow I need it to scroll with the last digit on the QLabel我用 pyqt5 制作了一个计算器,但是当计算器 QLabel 溢出时,我需要它用 QLabel 上的最后一位数字滚动

在此处输入图片说明

One option is to use a read-only QLineEdit instead of a QLabel .一种选择是使用只读QLineEdit而不是QLabel For example例如

from PyQt5 import QtWidgets, QtGui
from PyQt5.QtCore import Qt


class Window(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()

        self.label = QtWidgets.QLineEdit()
        # mimic QLabel by making self.label read-only and removing the frame and background color
        self.label.setReadOnly(True)
        self.label.setStyleSheet("background-color:#00000000; font-size: 20px; border:0px")
        self.label.setAlignment(Qt.AlignCenter)

        self.text_edit = QtWidgets.QLineEdit(self)
        self.text_edit.setPlaceholderText('type something')

        self.vlayout = QtWidgets.QVBoxLayout(self)
        self.vlayout.addWidget(self.label)
        self.vlayout.addWidget(self.text_edit)

        self.text_edit.textChanged.connect(self.label.setText)


if __name__ == '__main__':
    app = QtWidgets.QApplication([])
    window = Window()
    window.show()
    app.exec()

Screenshots:截图:

截图 1 截图 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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