tags:

views:

19

answers:

3

Hi all, I am new to Qt application development. In my Application i have built a QWERTY keypad usign QSignalMapper.I have 3 QLineEdit boxes above this keypad area. Now, when ever i select any line, i didnt get to know which line object gets selected.

If i subclass QLineEdit, and Reimplement this, than also i am not knowing which particular line has the current focus.If i presses line edit box, and start typing into that with keypad, focus moves to keypad's button.

Than,how can i get to know which line edit has been selected?

+1  A: 

You can override QLineEdit::focusInEvent in order to remember which line edit was last focused.

laalto
A: 

I have override QLineEdit with MyLineEdit. But still my problem didnt get solved.

My code:

class MyLineEdit : public QLineEdit

{

Q_OBJECT

public:

MyLineEdit(QWidget *parent = 0);

~MyLineEdit();

signals:

focussed(bool hasFocus);

protected:

virtual void focusInEvent(QFocusEvent *e);

virtual void focusOutEvent(QFocusEvent *e);

}

In the myLineEdit.cpp :

MyLineEdit::MyLineEdit(QWidget *parent)

: QLineEdit(parent)

{}

MyLineEdit::~MyLineEdit()

{}

void MyLineEdit::focusInEvent(QFocusEvent *e)

{

QLineEdit::focusInEvent(e);

curLineEdit=this;

QDebug()<<"Gained Focus";

curLineEdit.setText("test");

}

void MyLineEdit::focusOutEvent(QFocusEvent *e)

{

QLineEdit::focusOutEvent(e);

QDebug()<<"Lost Focus";

}

When i do take objects or MyLineEdit say L1,L2,L3.

and click on any one,than it Loops in a Infinite loop priting "Gained Focus"; AND Finally gets crashed.

I want to Identify a particular MyLineEdit object from the toplevel Widget, and take the appropriate action.what should i do?

mukesh
Try accepting the event by calling `e->accept();` as the the last command in your focus handler.
Wolfgang Plaschg
A: 

You can set your keypad buttons to never accept focus. This way, the focus won't leave the line edit when keypad buttons are pressed.

Caleb Huitt - cjhuitt