PDA

View Full Version : line edit focus



addu
16th July 2009, 14:47
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");
}
}
Then i overrided the QLineEdit KeyPressEvent.



class Con_Main : public QLineEdit
{
Q_OBJECT

public:
Con_Main(QWidget *parent = 0);
void keyPressEvent(QKeyEvent *e);
};



Con_Main::Con_Main(QWidget *parent = 0):QLineEdit(parent)
{
}
void Con_Main::keyPressEvent(QKeyEvent *e)
{
// e->ignore();
QMessageBox::information(0,"",QString("Con_main"));
}


I have doubt at KeyPressEvent to over ride this method, have to ignore the event .what i have to do here..

And it is giving the

error: default argument given for parameter 1 of `Con_Main::Con_Main(QWidget*)'
error: after previous specification in `Con_Main::Con_Main(QWidget*)'

Please help me

Thanks

Yuaraj R

jpn
16th July 2009, 14:57
How about using focusInEvent() and focusOutEvent() for clearing/restoring the place holder text? This is the way it traditionally works for example in browsers' search boxes.

addu
16th July 2009, 15:33
I am using the Keypressevent.

i am asking what mistake i ahve done in my code.

Thanks

Yuvaraj R

jpn
16th July 2009, 15:39
As for the compilation error, remove the default parameter value in your .cpp file. You already declared it in the .h file:


Con_Main::Con_Main(QWidget *parent = 0):QLineEdit(parent) // <-- remove "= 0"
{
}