Len*_*and 6 qt mouseevent mousewheel qtestlib qt5
我很高兴QTestLib为基于小部件的 UI 编写测试Qt5。直到现在,当我试图找到一种模拟鼠标滚轮事件的方法时,似乎并不缺乏特性和便利功能。
我已经查看了官方文档和官方示例,但我似乎不知道如何模拟鼠标滚轮事件。
这不存在吗?或者我错过了什么?我应该如何使用创建虚拟鼠标滚轮事件QTestLib?
对于 10 年后遇到这个问题的任何人。我们为 Qt4.8 的测试套件编写了一个实现(也在 Qt5.6 中进行了测试,一如既往地没有保证):
void TestUtility::mouseWheelTurn(
QWidget *widget, // The most top level widget; a MainWindow in our case
int delta, // As in QWheelEvent
QPoint pos, // Mouseposition in the moment of scrolling relative to top level widget
Qt::MouseButtons buttons, // As in QWheelEvent
Qt::KeyboardModifiers modifiers, // As in QWheelEvent
Qt::Orientation orientation, // As in QWheelEvent
int delay) // As in other QTest functions
{
QWidget *toWheelChild = widget->childAt(pos);
if(toWheelChild == NULL) return;
pos = widget->mapToGlobal(pos);
pos = toWheelChild->mapFromGlobal(pos);
QTest::mouseMove(toWheelChild, pos);
QTest::qWait(delay);
QWheelEvent *wheelEvent =
new QWheelEvent(pos, delta, buttons, modifiers, orientation);
QApplication::instance()->postEvent(toWheelChild, wheelEvent);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1045 次 |
| 最近记录: |