滚动字幕有两种,一种是左右滚动,一种是上下滚动。
现在介绍一下上下滚动,利用QEditText控件实现。
上代码:
_fromUtf8 = QMetaType.QString.fromUtf8
self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName(_fromUtf8("centralwidget")) self.textEdit = QTextEdit(self.centralwidget) self.textEdit.setGeometry(QRect(350, 40, 401, 380)) self.textEdit.setObjectName(_fromUtf8("textEdit")) self.font = QFont(_fromUtf8('微软雅黑, verdana'), 10) self.textEdit.setFont(self.font) self.textEdit.setPlainText( "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n1\n2\n3\n4\n5\n6\n7\n8\n9\n") self.textEdit.append("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") self.min = self.textEdit.verticalScrollBar().minimum() self.t = QTimer() self.t.timeout.connect(self.changeTxtPosition)
def changeTxtPosition(self): self.textEdit.verticalScrollBar().setValue(self.min) self.min += 1 if self.min == self.textEdit.verticalScrollBar().maximum(): self.min = self.textEdit.verticalScrollBar().minimum()