views:

103

answers:

1

Hi Guys,

I am stuck in the middle of this problem for a week or so now, I found a similar question posted on Qt for Symbian forum, but no body answered it.

The problem is simply that when I run the application, well it is still not an application just a prototype :), either on the emulator or on a real device, and use the physical QWERTY keyboard to type normal characters, in this case the device is in landscape orientation, the function keyPressEvent is not called, but it is called if I pressed keys such as enter, backspace, different arrows and the action key. Also this happens if I run the application on the emulator and used the development machine keyboard to type.

On the other hand, if I used the on screen mini QWERTY keyboard on the emulator, or used the development machine keyboard to type and the emulator is in portrait orientation, the keyPressEvent function get called.

Now to be more specific, I have a class that inherits from QTextEdit, I override the functions keyPressEvent and focusInEvent inside it, also I call the function setFocusPolicy inside the constructor of the class, but nothing seems to solve the problem.

Also I have to say that the code I am trying on is a modified version of the example customcompleter, and found that this issue also happens with the original code.

So guys, any one has any idea about how to solve this issue?

Regards.

+1  A: 

You might check keyReleaseEvent and/or monitor all events by overriding event(QEvent*) and verifying exactly what events are indeed being generated. A different suitable event might be being generated.

However, the behavior you've described really sounds like a bug to me. You might check the Qt Bug Tracker and/or file a bug report.

Kaleb Pederson
Kaleb, thank you so much, I don't know how never occurred to me to try this function!! Now, this function is called when I press any key, but there is still some problems, so I thought about overriding event(QEvent *) in my subclass, but it doesn't get called at all, so do you have any idea why is that??
Ayman
`event(QEvent*)` is the main event dispatcher for all QWidgets, so it will be called if your widget is handling events. If you're not seeing events and your widget is indeed receiving events -- verify that you have the correct signature.
Kaleb Pederson
Well, here is the code for my classclass MyWidget : public QTextEdit { Q_OBJECTpublic: MyWidget(QWidget *parent=0); void keyPressEvent(QKeyEvent * event); void keyReleaseEvent(QKeyEvent * event ); bool event(QKeyEvent *event);};MyWidget::MyWidget(QWidget *parent):QTextEdit(parent){ setText("Hola");}void MyWidget::keyPressEvent(QKeyEvent *event){ QWidget::keyPressEvent(event);}void MyWidget::keyReleaseEvent(QKeyEvent *event){ QWidget::keyReleaseEvent(event);}bool MyWidget::event(QKeyEvent *event){ QWidget::event(event);}
Ayman
Look carefully, what you have doesn't match. You have `bool MyWidget::event(QKeyEvent*)` which uses a different parameter.
Kaleb Pederson
You are right Kaleb, my bad, i didn't notice this mistake, but you know something, also after correcting this it is still not entering the function keyPressEvent, this is really very weird, I can't understand why this is happening.
Ayman
Like I said, it may be a bug. Using a different, substitutable event such as `keyReleaseEvent` may be useful if it works for you.
Kaleb Pederson
Well, it works, but not in all cases. By the way, a friend of mine reported this bug to Nokia, we will see what they say and let you know. Thank you.
Ayman