I am trying to send keypress event to the focus widget.
QKeyEvent keyEvent
(QEvent::KeyRelease,keyId, Qt
::NoModifier, text,
false,
1);
QKeyEvent keyEvent(QEvent::KeyRelease,keyId, Qt::NoModifier, text, false, 1);
QCoreApplication::sendEvent(m_focusedWd, &keyEvent);
To copy to clipboard, switch view to plain text mode
But it is not working.
Same thing in a different way
keyboard class:
QKeyEvent keyEvent
(QEvent::KeyRelease,keyId, Qt
::NoModifier, text,
false,
1);
QKeyEvent keyEvent(QEvent::KeyRelease,keyId, Qt::NoModifier, text, false, 1);
QCoreApplication::sendEvent(m_activeWindow, &keyEvent);
To copy to clipboard, switch view to plain text mode
Mainwindow:
QKeyEvent keyEvent
(QEvent::KeyPress,event
->key
(),event
->modifiers
(),event
->text
(),
false,
1);
QKeyEvent keyEvent(QEvent::KeyPress,event->key(),event->modifiers(),event->text(),false,1);
QApplication::sendEvent(this->focusWidget(),&keyEvent);
To copy to clipboard, switch view to plain text mode
It is working. I am able to send text to line edit.
But problem is if I press enter then it will in infinite loop and after a while program will crash.
But i tried QInputMethodEvent in keyboard class.
ev.setCommitString(text);
QInputMethodEvent ev;
ev.setCommitString(text);
QCoreApplication::sendEvent(m_focusedWd,&ev);
To copy to clipboard, switch view to plain text mode
I am able to set text only.
How i will send backspace kind of special key ?
Why keypress event is not able to send to focus widget ?
thanks.
Bookmarks