[Qt-interest] line edit focus problem
Tony Rietwyk
tony.rietwyk at rightsoft.com.au
Thu Jul 16 14:11:48 CEST 2009
-----Original Message-----
Hi All
I have set the line edit text as default by "Dial number"
When i pressing the keys in keyboard ,then i am clearing the lineedit text
and inserting the pressed key value in line edit..
if i set lineEdit in setfocusby default..
that time any key events is not uptating ..
if diable the forucs for line edit.. key event are updating..
Sample code..
ui.lineEdit.setText("Dial Number")
void MainWindow::keyPressEvent(QKeyEvent *e)
{
switch(e->key)
{
case Key_0 :
if(ui.lineEdit.Text == "Dial Number")
{
ui.lineEdit.clear }
ui.lineEdit.insert("0");
break;
case Key_1 :
if(ui.lineEdit.Text == "Dial Number")
{
ui.lineEdit.clear }
ui.lineEdit.insert("1");
}
}
Please help , what's wrong with me
Thanks
Yuvaraj R
There is nothing wrong!
You are listening to the events on the main window, and it only gets the key
strokes when the edit doesn't have focus.
I suggest to either:
- use the same code, but subclass from QLineEdit,
- or use
ui.lineEdit->installEventFilter( this );
and override the eventFilter method in MainWindow.
I normally take the second option.
Tony.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090716/2f34d20d/attachment.html
More information about the Qt-interest-old
mailing list