c++ - QTextEdit 和自定义滚动 - PageDown/PageUp

标签 c++ qt user-interface qtextedit qabstractslider

我正在尝试在 QTextEdit 中实现自定义滚动行为控制。它似乎工作正常,但我在使用 PageDown/PageUp 按键时遇到问题:我正在通过 actionTriggered 控制滚动行为信号,因为文档说明:

When the signal is emitted, the sliderPosition has been adjusted according to the action, but the value has not yet been propagated (meaning the valueChanged() signal was not yet emitted), and the visual display has not been updated. In slots connected to this signal you can thus safely adjust any action by calling setSliderPosition() yourself, based on both the action and the slider's value.

并使用我需要从那里到达的 sliderPosition 启动 QTimer(例如,我每次递增 value() 以到达 sliderPosition).不幸的是,每次我按下 PageUp/PageDown 键时,还会出现另一个 setValue。 () 函数调用由插入符号触发,插入符号由 PageUp/PageDown 键移动,它会自动将滚动条值移动到动画的末尾。

调用堆栈显示:

QAbstractSlider::setValue(int)
??
QMetaObject::activate(QObject*, int, int, void**)   
QWidgetTextControl::visibilityRequest(QRectF const&)    
QWidgetTextControl::ensureCursorVisible()  <--
QWidgetTextControl::setTextCursor(QTextCursor const&)   <--
QTextEdit::keyPressEvent(QKeyEvent*)
QWidget::event(QEvent*)
QFrame::event(QEvent*)
QAbstractScrollArea::event(QEvent*)
QTextEdit::event(QEvent*)
QApplicationPrivate::notify_helper(QObject*, QEvent*)
QApplication::notify(QObject*, QEvent*)
QCoreApplication::notifyInternal(QObject*, QEvent*)
...

我不知道如何在插入符因 PageUp/PageDown 按键而移动时阻止插入符发出 QAbstractSlider::SetValue() 调用。

如有任何帮助,我们将不胜感激。

最佳答案

好吧,那就用

disconnect(receiver, SLOT(setValue...), unwanted_sender, SIGNAL(...))

断开特定的不需要的连接。

关于c++ - QTextEdit 和自定义滚动 - PageDown/PageUp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25960026/

相关文章:

c++ - 如何在 C++ 中手动运行消息泵

qt - 在 Qt 中,我可以 QWebFrame::print() 提供额外的渲染层吗?

c++ - 动态覆盖

android - 多列中的项目 - 微调器

python - 编译Boost.Python代码报错: library not found for -lpython3. 6m

c++ - Protocol Buffer : Maximum memory size for the Arena

php - 如何从 COM DLL 返回包含多个空字符的 BSTR

qt - QScrollArea清除背景颜色

c++ - 避免 GUI 在多线程操作时卡住

user-interface - 通过输入前几个字符跳转到列表框项目