Results 1 to 5 of 5

Thread: Focus problem

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Focus problem

    This should be simple, but I can't get it to work right.
    I have two display objects for some database data, one a table view and one a dialog.
    The table view shows multiple records and the dialog shows a single record view.
    Depending on saved preferences, one or the other opens on application start up.
    If the table view opens, the focus returns to the main window. If the dialog opens, the focus stays on the dialog, not the main window. The dialog is non-modal.
    There is a pushbutton on the main window to switch between the two displays.
    If you switch to the table view, the focus returns to the main window, if you switch to the dialog, the focus stays on the dialog. I have added the following code both on application start up and on display switching to try and force the focus back to the main window after the dialog opens, but it isn't doing it.

    Any suggestions?

    Qt Code:
    1. MainWindow::close();
    2. MainWindow::show();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Focus problem

    QWidget-setFocus() may be of help.

    Have a look at QWidget->activateWindow(), too.

  3. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Focus problem

    Thanks, but I forgot to mention that I tried setting the focus to a widget in the main window - unfortunately, to no effect.

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Focus problem

    Quote Originally Posted by waynew View Post
    Thanks, but I forgot to mention that I tried setting the focus to a widget in the main window - unfortunately, to no effect.
    Yeah. I think activateWindow() might be a better bet.

    I'm assuming you can manually activate the main window by clicking on it. If not, there may be a modeless/modal issue with your dialog.

  5. #5
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Focus problem

    Tried that, no luck. Same problem.

Similar Threads

  1. QLineEdit focus problem
    By matteo.cozzaglio in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2009, 14:13
  2. QDialog derived and focus problem
    By elm66 in forum Qt Programming
    Replies: 1
    Last Post: 4th April 2008, 21:52
  3. QX11EmbedContainer problem with focus
    By PhoenixRevived in forum Qt Programming
    Replies: 0
    Last Post: 14th November 2007, 05:34
  4. QGraphicsTextItem focus problem
    By Gopala Krishna in forum Qt Programming
    Replies: 5
    Last Post: 26th June 2007, 17:25
  5. Tab/Enter focus problem
    By b1 in forum Qt Programming
    Replies: 4
    Last Post: 23rd October 2006, 23:34

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.