Qt: send Key_Return and Key_Delete events

I am developing a virtual keyboard with Qt Embedded and I ran into a little problem. In fact, I use SignalMappers to map the key to keyboard events to display text in QTextEdit widgets.

Everything works fine, except for two events: Key_Return and Key_Delete; I have no idea what I'm doing wrong, maybe you will have an idea.

Here is the classic code to send characters:

void VirtualKeyboard::SendChar( int index ) { QChar charToSend( letters_.at( index )->text().at( 0 ) ); // Get char server_->sendKeyEvent( charToSend.unicode(), QEvent::KeyPress, Qt::NoModifier, true, false ); } 

letters_ is a QVector containing QPushButton *, and server_ is an instance of QWSServer; this code is working fine. Now, for example, with backspace:

 void VirtualKeyboard::SendBackspace() { server_->sendKeyEvent( Qt::Key_Backspace, Qt::Key_Backspace, Qt::NoModifier, true, false ); } 

This code works great. And the code that doesn't work:

 void VirtualKeyboard::SendDelete() { server_->sendKeyEvent( Qt::Key_Delete, Qt::Key_Delete, Qt::NoModifier, true, false ); } void VirtualKeyboard::SendEnter() { server_->sendKeyEvent( 0x01000004, Qt::Key_Return, Qt::NoModifier, true, false ); } 

As you can see, I tried to set the unicode value, but that will not help; Could you help me?

Thanks!


RESOLVED WITH THE FOLLOWING CODE (SEE COMMENT):

 void TextEdit::DeleteEvent() { if( cursor_.hasSelection() ) { // Delete selection cursor_.removeSelectedText(); } else { // Delete right char cursor_.deleteChar(); } setTextCursor( cursor_ ); } void TextEdit::ReturnEvent() { cursor_.insertText( "\n" ); setTextCursor( cursor_ ); } 

cursor_ is the QTextCursor attribute initialized by this line:

 cursor_ = textCursor(); 
+4
source share
1 answer

RESOLVED WITH THE FOLLOWING CODE (SEE COMMENT):

 void TextEdit::DeleteEvent() { if( cursor_.hasSelection() ) { // Delete selection cursor_.removeSelectedText(); } else { // Delete right char cursor_.deleteChar(); } setTextCursor( cursor_ ); } void TextEdit::ReturnEvent() { cursor_.insertText( "\n" ); setTextCursor( cursor_ ); } 

cursor_ is the QTextCursor attribute initialized by this line:

 cursor_ = textCursor(); 
+2
source

Source: https://habr.com/ru/post/1382844/


All Articles