Results 1 to 4 of 4

Thread: Focus in lineEdit in QMDISubWindow

  1. #1
    Join Date
    Mar 2009
    Posts
    9
    Thanks
    1
    Qt products
    Qt4

    Default Focus in lineEdit in QMDISubWindow

    Hi people!

    I have a problem, I need put focus in lineEdit in QMDISubWindow, but same put the command:

    ui->tbConsulta->setFocus();

    The Widget don't get focus.

    How fix this?

    Thks.

    Hugs.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Focus in lineEdit in QMDISubWindow

    Is the sub window containing the widget the active MDI sub window or not? The focus only visibly changes in the active sub window although it has changed in the other sub-windows too. Does this help?
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class MyWidget: public QWidget
    4. {
    5. Q_OBJECT
    6. public:
    7. MyWidget(QWidget *p = 0): QWidget(p) {
    8. edit1 = new QLineEdit(this);
    9. edit2 = new QLineEdit(this);
    10.  
    11. QVBoxLayout *layout = new QVBoxLayout;
    12. layout->addWidget(edit1);
    13. layout->addWidget(edit2);
    14.  
    15. setLayout(layout);
    16. edit1->setFocus();
    17.  
    18. QTimer::singleShot(5000, edit2, SLOT(setFocus())); // switch focus in 5 seconds
    19. }
    20. private:
    21. QLineEdit *edit1;
    22. QLineEdit *edit2;
    23. };
    24.  
    25. int main(int argc, char *argv[])
    26. {
    27. QApplication app(argc, argv);
    28.  
    29. QMdiArea m;
    30. m.addSubWindow(new MyWidget);
    31. m.addSubWindow(new MyWidget);
    32. m.show();
    33. return app.exec();
    34. }
    35. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    Last edited by ChrisW67; 27th January 2011 at 23:26. Reason: updated contents

  3. #3
    Join Date
    Mar 2009
    Posts
    9
    Thanks
    1
    Qt products
    Qt4

    Default Re: Focus in lineEdit in QMDISubWindow

    Hi! Thks for your attentation.

    This command:

    QTimer::singleShot(5000, edit2, SLOT(setFocus()));

    Worked, but I think that this is a palliative, at least to me, but resolved my problem.

    Thks another time.

    Hugs.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Focus in lineEdit in QMDISubWindow

    The single shot timer was only there to provide something to change the focus in the example and demonstrate that focus does move. It doesn't fix any problem.

Similar Threads

  1. QMdiSubWindow stays always on top
    By SiS-Shadowman in forum Qt Programming
    Replies: 0
    Last Post: 20th July 2010, 17:55
  2. QMdiSubWindow keyPressEvent
    By M. in forum Newbie
    Replies: 0
    Last Post: 4th December 2009, 23:05
  3. LineEdit / SpinBox focus in problem
    By Sethest in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2008, 13:06
  4. QMdiSubWindow resizing in 4.3
    By kalpa in forum Qt Programming
    Replies: 0
    Last Post: 4th June 2007, 13:39
  5. Focus issues / Setting multiple focus
    By ComputerPhreak in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2007, 06:09

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.