[英]How can I make my QLabel scroll with the written text
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:截图:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.