向聚焦控件投递事件
if(qApp->focusWidget())
QApplication::postEvent(qApp->focusWidget(),
new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier));
若要投递数字或字母
if(qApp->focusWidget())
QApplication::postEvent(qApp->focusWidget(),
new QKeyEvent(QEvent::KeyPress,QChar('0').unicode(), Qt::NoModifier,QString(QChar('0'))));
做键盘的时候用到
sendEvent模拟鼠标点击
QPoint pos(0,0);
QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QApplication::sendEvent(QWidget::focusWidget(), &event0);