Skip to content

Commit

Permalink
Working on a testing issue on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
pyushkevich committed Oct 1, 2024
1 parent 47974a4 commit fcbaa93
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
35 changes: 21 additions & 14 deletions Testing/GUI/Qt/SNAPTestQt.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,24 @@ void SNAPTestQt::application_exit(int rc)
Q_ARG(int, rc));
}

void SNAPTestQt::postKeyEventInternal(QObject *object, QString key)
{
QWidget *widget = dynamic_cast<QWidget *>(object);
if(widget)
{
QKeySequence seq(key);
if(seq.count() == 1)
{
QKeyCombination code = seq[0];
Qt::Key key = code.key();
Qt::KeyboardModifiers mods = code.keyboardModifiers();

QKeyEvent *ev = new QKeyEvent(QEvent::KeyPress, key, mods);
QApplication::postEvent(widget, ev);
}
}
}

void SNAPTestQt::sleep(int milli_sec)
{
// Scale requested sleep time by acceleration factor
Expand Down Expand Up @@ -332,20 +350,9 @@ void SNAPTestQt::postMouseEvent(QObject *object, double rel_x, double rel_y, QSt

void SNAPTestQt::postKeyEvent(QObject *object, QString key)
{
QWidget *widget = dynamic_cast<QWidget *>(object);
if(widget)
{
QKeySequence seq(key);
if(seq.count() == 1)
{
QKeyCombination code = seq[0];
Qt::Key key = code.key();
Qt::KeyboardModifiers mods = code.keyboardModifiers();

QKeyEvent *ev = new QKeyEvent(QEvent::KeyPress, key, mods);
QApplication::postEvent(widget, ev);
}
}
// We need the code to run in the main thread
QMetaObject::invokeMethod(
this, "postKeyEventInternal", Qt::QueuedConnection, Q_ARG(QObject *, object), Q_ARG(QString, key));
}


Expand Down
4 changes: 4 additions & 0 deletions Testing/GUI/Qt/SNAPTestQt.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public slots:

static void application_exit(int rc);

protected slots:

void postKeyEventInternal(QObject *object, QString key);

protected:

ReturnCode ListTests();
Expand Down

0 comments on commit fcbaa93

Please sign in to comment.