Results 1 to 5 of 5

Thread: QLineEdit setFocus

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default QLineEdit setFocus

    Hey there, I'm using that call to set the focus on my QLineEdit widget.

    Qt Code:
    1. /* virtual */ void ZeConversationWidget::showEvent(QShowEvent * event)
    2. {
    3. mConversationInput->getMessageInput().setFocus();
    4. }
    To copy to clipboard, switch view to plain text mode 

    I don't get any focus.
    But when I do resize the window, strangely enough the focus is suddenly set on that QLineEdit, and it works.

    I'm using 4.4 release candidate.

    Has anyone got an idea?

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit setFocus

    Hi,

    From QWidget doc:

    Be aware that if the widget is hidden, it will not accept focus until it is shown.

    So, if the widget is not shown yet, it don't will get the focus.
    Òscar Llarch i Galán

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit setFocus

    For such things use singleShot to set the data values etc, related to showing of widgets etc
    QTimer::singleShot(0,this,initialize());
    MyWindow::initialize()
    {
    mConversationInput->getMessageInput().setFocus();
    }
    Hope this helps

  4. #4
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QLineEdit setFocus

    I did a check with isVisible :

    Qt Code:
    1. /* virtual */ void ZeConversationWidget::showEvent(QShowEvent * event)
    2. {
    3. if (mConversationInput->getMessageInput().isVisible())
    4. {
    5. // My code gets here
    6. std::cout << "Hello\n";
    7. mConversationInput->getMessageInput().setFocus();
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QLineEdit setFocus

    Quote Originally Posted by aamer4yu View Post
    For such things use singleShot to set the data values etc, related to showing of widgets etc


    Hope this helps
    Tried that one too, no success. I need to resize my window to get focus.
    I think it might be a QT 4.4 bug.

Similar Threads

  1. QLineEdit and focus
    By serega in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2008, 00:49
  2. how to get last character of QLineEdit
    By yagabey in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2008, 16:38
  3. QValidator, regular expressions and QLineEdit
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 01:25
  4. QAction shortcuts from QLineEdit
    By discostu in forum Qt Programming
    Replies: 3
    Last Post: 4th March 2007, 15:43
  5. a box around QLineEdit?
    By GreyGeek in forum Qt Tools
    Replies: 13
    Last Post: 8th February 2006, 15:40

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.