PDA

View Full Version : QLineEdit keyPressEvent problem



impeteperry
26th November 2007, 16:23
Hi (running Kubuntu 7.04 )
I have 2 QLineEdits
Step 1: The first one has the focus, the second one is not enabled.
I enter some text in first one and press the <enter> key which sends the text to a function. This is what I want
Step 2: This function now disables the first QLineEdit and enables the second one and sets the focus there.
I enter some text and press the <enter> key to send this text to another function, but nothing happens.

I am using signal & slots "emit sendInput(QString) ....SLOT(receivedInput(QString)
Where the <QStrings> are the text in the particular widget.

I am totally confused as to why when the first has the text, the <return> works and when the second one has the text, the <enter> does not.

Thanks for help in advance.

wysota
26th November 2007, 16:36
We'd have to see the code. Also make sure connection statements are correct.

impeteperry
26th November 2007, 21:36
Hi here goes:
There are 3 attachements Select a group, name a group, and a populated index.
The program is part of a study I am making on program interfaces for non-computer people. The index is for a disc storage system "discgear" which I use. I have no connection with discgear except using their products.

I have tried to extract just enough code to see where the problem is. Thanks

//--------------------------------------------------------------keypress functions
void BaseForm::slotFromKeyboard()
{
if ( functionNumber == 2 )
{
if( ui.le1.hasFocus() == true ) emit returnGroupListNumber( &ui.le1->text() );
else if( ui.le2.hasFocus() == true ) emit returnGroupListName( &ui.le2->text() );
}
}
//-------------------------------------------------------------signal/slot items
connect ( this, SIGNAL ( returnGroupListNumber ( QString * ) ), pb2Functions, SLOT ( slotReturnGroupListNumber ( QString * ) ) );
connect ( this, SIGNAL ( returnGroupListName( QString * ) ), pb2Functions, SLOT ( slotReturnGroupListName ( QString * ) ) );


//--------------------------------------------------------------- in the pb2headerfile:
void slotReturnGroupListNumber( QString * );
void slotReturnGroupListName ( QString * );

//---------------------------------------------------------------in the pb2cpp file: the functions themselves
void PB2::slotReturnGroupListNumber( QString *item )
{
k = *item;
emit setEnabledItems( "n||y||n||n||n" ); // disable 1st, enable 2nd
emit setFocusItems( "n||y||n||n||n" ); // no focus on 1st, set focus on 2nd
k = "You have selected <Group> " + *item + ".\n";
k += "If the <Yellow> box is empty, enter a name for this group.\n";
k += "If there is a name in the <box> you may edit it.\n";
k += "When it is what you want press the <enter> key.";
emit setMessageBox( k );
//----------------------------------------------------------------------Second slot function items
}
void PB2::slotReturnGroupListName( QString *item )
{
h = *item;
}


Thanks for any help and/or comments about what I am trying to do

wysota
26th November 2007, 23:14
Why are you emitting pointers to QStrings? I was hoping you would show us event handlers and places where you emit signals.

impeteperry
27th November 2007, 04:28
Thanks for the comments, but I am not sure i know what you are asking. but here are the signals for the "return" items
void returnGroupListNumber( QString * );
void returnGroupListName( QString * );I am sure there are better ways to do what I want, but my knowledge is limited

as you can see from the third snapshot, I have a working version, but what I want to do here is develop a consistant "User" interface where all functions are selected by function key, Info keyed in and the <enter> key pressed, that is (FunctionKey) (Type Text) (Enter Key).That is the total program.

But asside from the style of programming, what I would like to know is why when i key in text in one QLineEdit widget, press the <enter> key and it sends a string (or a pointer in this case) to a function and then the process is repeated for another QLineEdit and pressing the <return> key has no effect.

I appreciate your indulgence and if this is not the right place for questions of this type please let me know.

pete perry

wysota
27th November 2007, 10:21
But asside from the style of programming, what I would like to know is why when i key in text in one QLineEdit widget, press the <enter> key and it sends a string (or a pointer in this case) to a function and then the process is repeated for another QLineEdit and pressing the <return> key has no effect.

I don't know that because you didn't provide the code that handles those return presses. You only provided some methods without showing us how you actually use them. Your goal is very simple to obtain and you have written quite a complex code here. Maybe instead of trying to fix your code, redesign it.

I'm not really sure why you emit so many custom signals and what is connected to them.

From what I can see you have some line edits and you want to react on situations when someone finished editing each of the line edits to do some task. In that case it'd be enough to connect custom slots to editingFinished() signals of the line edits and just switch the focus to the next line edit there.

If you want, I can provide you a skeleton of code that does more or less what you want.

impeteperry
27th November 2007, 16:57
Thanks again
From what I can see you have some line edits and you want to react on situations when someone finished editing each of the line edits to do some task. In that case it'd be enough to connect custom slots to editingFinished() signals of the line edits and just switch the focus to the next line edit there. is exactly what I want to do and IT WORKS!!
Thanks a million