Results 1 to 7 of 7

Thread: QLineEdit keyPressEvent problem

  1. #1
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QLineEdit keyPressEvent problem

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QLineEdit keyPressEvent problem

    We'd have to see the code. Also make sure connection statements are correct.

  3. #3
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QLineEdit keyPressEvent problem

    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
    Qt Code:
    1. //--------------------------------------------------------------keypress functions
    2. void BaseForm::slotFromKeyboard()
    3. {
    4. if ( functionNumber == 2 )
    5. {
    6. if( ui.le1.hasFocus() == true ) emit returnGroupListNumber( &ui.le1->text() );
    7. else if( ui.le2.hasFocus() == true ) emit returnGroupListName( &ui.le2->text() );
    8. }
    9. }
    10. //-------------------------------------------------------------signal/slot items
    11. connect ( this, SIGNAL ( returnGroupListNumber ( QString * ) ), pb2Functions, SLOT ( slotReturnGroupListNumber ( QString * ) ) );
    12. connect ( this, SIGNAL ( returnGroupListName( QString * ) ), pb2Functions, SLOT ( slotReturnGroupListName ( QString * ) ) );
    13.  
    14.  
    15. //--------------------------------------------------------------- in the pb2headerfile:
    16. void slotReturnGroupListNumber( QString * );
    17. void slotReturnGroupListName ( QString * );
    18.  
    19. //---------------------------------------------------------------in the pb2cpp file: the functions themselves
    20. void PB2::slotReturnGroupListNumber( QString *item )
    21. {
    22. k = *item;
    23. emit setEnabledItems( "n||y||n||n||n" ); // disable 1st, enable 2nd
    24. emit setFocusItems( "n||y||n||n||n" ); // no focus on 1st, set focus on 2nd
    25. k = "You have selected <Group> " + *item + ".\n";
    26. k += "If the <Yellow> box is empty, enter a name for this group.\n";
    27. k += "If there is a name in the <box> you may edit it.\n";
    28. k += "When it is what you want press the <enter> key.";
    29. emit setMessageBox( k );
    30. //----------------------------------------------------------------------Second slot function items
    31. }
    32. void PB2::slotReturnGroupListName( QString *item )
    33. {
    34. h = *item;
    35. }
    To copy to clipboard, switch view to plain text mode 

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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QLineEdit keyPressEvent problem

    Why are you emitting pointers to QStrings? I was hoping you would show us event handlers and places where you emit signals.

  5. #5
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QLineEdit keyPressEvent problem

    Thanks for the comments, but I am not sure i know what you are asking. but here are the signals for the "return" items
    Qt Code:
    1. void returnGroupListNumber( QString * );
    2. void returnGroupListName( QString * );
    To copy to clipboard, switch view to plain text mode 
    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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QLineEdit keyPressEvent problem

    Quote Originally Posted by impeteperry View Post
    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.

  7. #7
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QLineEdit keyPressEvent problem

    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

Similar Threads

  1. QLineEdit - lostFocus signal problem
    By Enygma in forum Qt Programming
    Replies: 6
    Last Post: 17th June 2010, 20:52
  2. keyPressEvent problem
    By amulya in forum Qt Programming
    Replies: 4
    Last Post: 22nd January 2008, 13:16
  3. Problem Euro Sign with QLineEdit
    By Kubil in forum Qt Programming
    Replies: 1
    Last Post: 24th August 2007, 04:56
  4. KeyPressEvent and QLineEdit question
    By impeteperry in forum Qt Programming
    Replies: 1
    Last Post: 21st August 2007, 16:18
  5. Problem with QLineEdit and setText
    By Elmo23x in forum Qt Programming
    Replies: 8
    Last Post: 12th April 2007, 12:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.