Results 1 to 5 of 5

Thread: Tab/Enter focus problem

  1. #1
    Join Date
    Jun 2006
    Posts
    64
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Tab/Enter focus problem

    G'Day All,

    I have a simple function called from a QLineEdit on form A.

    connect( lineEdit, SIGNAL( editingFinished( ) ), this, SLOT( checkMainDatabase() ) );

    When I enter some data in the lineEdit and press "Enter", the function checks the main database and if not found opens the "add new data" form, B, and the focus is then on the new form, B. This part works as I planned.

    My problem is this: when I press "tab" instead of "Enter" the same thing happens except that form B is placed behind the original form, A, and focus is set on the next QlineEdit, lineEdit_2 in form A.

    By clicking on the "add new data" form the focus changes and all works normally. It is just annoying having to go throught the process of regaining the focus.

    I am guessing the reason is that a "tab" from a QLineEdit causes the focus to changed to the next (in my case) QLineEdit on the original form whereas an "Enter" indicates editing finished and focus is changed by the progam code as I have written.

    I have tried putting a setFocus command in the checkMainDatabase() function as a work around but to no avail. I have tried setting focus to the form B and widgets within the form.

    Is there a way around this? Any thoughts or suggested reading would be appreciated.


    Cheers, B1.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Tab/Enter focus problem

    Try adding these lines to where you show the "form B":
    Qt Code:
    1. formB->show(); // you have already this
    2. formB->raise(); // <--- add this
    3. formB->activateWindow(); // <--- and this
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Jun 2006
    Posts
    64
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tab/Enter focus problem

    Thanks for the reply JPN.

    Unfortunately it didn't work. I have posted the code for the function below.

    This is the call to open formB.

    Thanks, b1.



    Qt Code:
    1. void BackOrderForm::checkMainDatabase()
    2. {
    3. if (!lineEdit->text().isEmpty())
    4. {
    5. temppartnumber = lineEdit->text();
    6. checkmaindqry.prepare( "SELECT description, brand FROM dbparts WHERE boffinspartno=(\'"+temppartnumber+"\')" );
    7. checkmaindqry.exec();
    8. checkmaindqry.next();
    9. if (checkmaindqry.isValid())
    10. {
    11. lineEdit_2->setText(checkmaindqry.value(0).toString());
    12. lineEdit_6->setText(checkmaindqry.value(1).toString());
    13. }
    14. else
    15. {
    16. TempNewPart = lineEdit->text();
    17. formB = new UIDisplayPart::UIDisplayPart;
    18. connect( formB->okButton, SIGNAL( clicked() ), this, SLOT( updateText() ) );
    19. formB->show();
    20. formB->raise();
    21. formB->activateWindow();
    22. formB->lineEdit_2->setFocus();
    23. }
    24. TempNewPart = "";
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tab/Enter focus problem

    Quote Originally Posted by b1 View Post
    formB = new UIDisplayPart::UIDisplayPart;
    ...
    formB->show();
    formB->raise();
    formB->activateWindow();
    QWidget::activateWindow() won't work for windows that aren't shown and new windows are shown after the control goes back to the event loop.

    This might work:
    Qt Code:
    1. void BackOrderForm::activateFormB()
    2. {
    3. formB->activateWindow();
    4. }
    5. ...
    6. QTimer::singleShot( 0, this, SLOT( activateFormB() ) );
    7. // or if you don't like timers:
    8. // QMetaObject::invokeMethod( this, "activateFormB", Qt::QueuedConnection );
    To copy to clipboard, switch view to plain text mode 
    Another solution you can try is:
    Qt Code:
    1. formB->show();
    2. formB->raise();
    3. QApplication::processEvents(); // or QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
    4. formB->activateWindow();
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jun 2006
    Posts
    64
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tab/Enter focus problem

    Thanks for the reply, jacek.

    I tried all combinations of your suggestions and none work. I will go back to the drawing board and try recoding it all another way.

    Thanks for the help so far, b1.

Similar Threads

  1. Replies: 3
    Last Post: 26th September 2006, 12:16
  2. Replies: 2
    Last Post: 24th July 2006, 18:36
  3. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  4. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.