我正在尝试在 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/