如果有人在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);
}