如何编程滚动条在 QPlainTextEdit 或 QTextEdit 区域发生变化时跳转到底部/顶部?
如何编程滚动条在 QPlainTextEdit 或 QTextEdit 区域发生变化时跳转到底部/顶部? 貌似没有任何控制功能。
How to program scrollbar to jump to bottom/top in case of change in QPlainTextEdit or QTextEdit area?
It looks like it doesn't have any controlling function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
QTextEdit和QPlainTextEdit都继承自QAbstractScrollArea。 QAbstractScrollArea 对象通过verticalScrollBar() 方法提供对滚动条的访问。
因此,跳到顶部:
跳到底部:
这应该适用于 QTextEdit 和 QPlainTextEdit。
QTextEdit and QPlainTextEdit are both inherited from QAbstractScrollArea. The QAbstractScrollArea object provides access to the scrollbar through the verticalScrollBar() method.
Thus, to jump to the top:
And to jump to the bottom:
This should work for both QTextEdit and QPlainTextEdit.
您可以使用“ensureCursorVisible”方法:
不过,这不是一个插槽,因此您无法将其连接到任何信号 - 您必须自己创建一些可以连接到 void textChanged() 信号的东西。
免责声明:我可能误解了你的问题——我假设你想在文本附加一些文本时向下滚动。
You can use the 'ensureCursorVisible' method:
This is not a slot, though, so you can't connect it to any signal -- you'll have to create something yourself that you can connect to the void textChanged() signal.
Disclaimer: I may have misunderstood your question -- I assume you want to scroll down when some text is appended to the text.
当调整文本编辑控件的大小时,将调用
QWidget::resizeEvent
。您只需在子类中重写此函数,并调用verticalScrollBar ->; setValue (verticalScrollBar ->minimum())
(或maximum()
)。When a text edit control is resized,
QWidget::resizeEvent
is called. You just have to override this function in your subclass, and callverticalScrollBar -> setValue (verticalScrollBar -> minimum())
(ormaximum()
).我已经在Pyqt中完成了。
self.scrollArea.verticalScrollBar().rangeChanged.connect(self.change_scroll)
--------
I have done in Pyqt.
self.scrollArea.verticalScrollBar().rangeChanged.connect(self.change_scroll)
--------
在这里,我发布了我的解决方案,上述解决方案在我的案例中有效。
我想将光标置于
QTextbrowser
的开头。通过使用QTextEdit::setTextCursor,您可以将可见光标移动到您想要的位置:
希望,这会对某些人有所帮助并节省他们宝贵的时间。
Here I am posting my Solution as above solution dint work in my case.
I want to get the cursor at the beginning of
QTextbrowser
.By using QTextEdit::setTextCursor, you can move the visible cursor where you want:
Hope, it will help to some one and save their precious time.
我正在使用 QTextEdit 和
textEdit.verticalScrollBar().setValue(0)
对我不起作用。就我而言,
textEdit.moveCursor(QTextCursor.Start)
可以滚动到顶部。I am using QTextEdit and
textEdit.verticalScrollBar().setValue(0)
doesn't work for me.In my case,
textEdit.moveCursor(QTextCursor.Start)
can scroll to the top.