1 2 3 4 5 6 7 8 9 10 11 12
| void KeyPad::on_pushButton_1_clicked()
{
// Cas 1 : ne fonctionne pas
QKeyEvent *eventPress = new QKeyEvent(QEvent::KeyPress, Qt::Key_1, Qt::NoModifier, QChar(Qt::Key_1), false, 1);
QKeyEvent *eventRelease = new QKeyEvent( QEvent::KeyRelease, Qt::Key_1, Qt::NoModifier, QChar( Qt::Key_1 ), false, 1);
QCoreApplication::postEvent(ui->pushButton_1, eventPress);
QCoreApplication::postEvent(ui->pushButton_1, eventRelease);
// Cas 2 : ne fonctionne pas
QKeyEvent event(QEvent::KeyPress, Qt::Key_1, Qt::NoModifier, QChar(Qt::Key_1));
QApplication::sendEvent(this, &event);
} |
Partager