Results 1 to 6 of 6

Thread: Not getting focus on a QWindow on the initial show.

  1. #1
    Join Date
    Apr 2014
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Not getting focus on a QWindow on the initial show.

    My original issue was that I could not edit a QLineEdit on a QDialog when the dialog was initially shown. Other widgets worked as expected. To get around the problem, I had to click the QLineEdit then move the dialog window to a new location (or minimize/restore). I then clicked the QLineEdit again and was able to edit the contents. Thereafter all QLineEdits on the dialog were editable. This issue occurred on QDialogs in the app which contained QLineEdits.

    After several Google searches and attempting several of the suggestions, my problem space has shifted to not having focus on the dialog (now a QWindow) on the initial show. I always have to click on the body of the dialog once to get focus. Clicking the title bar or moving the dialog doesn't help. Thereafter any mouse click/edit operation works as expected. No widget (QLineEdit, QRadioButton, QPushButton, QCheckBox, QTableWidget) is functional until that initial click. The initial click does not perform the normal action if a widget, as opposed to a blank area, is selected. Focus always ends up on the first QLineEdit. Sending a mouse click event from the main window to the dialog, after the dialog is the active window/raised, does not help. Using set focus and focus proxy didn't help.

    The dialog is modeless. The QPushButtons, QCheckBoxes and QTableWidget have clink focus. The QRadioButtons have no focus. The QLineEdits have strong focus.

    Qt 4.6.3 (cannot upgrade)
    RHEL 5.5 (cannot upgrade)
    KDE Desktop (cannot change)

    How can I get focus on the dialog without the extra click?

    Thanks for your consideration

  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: Not getting focus on a QWindow on the initial show.

    Post the code that constructs the dialog UI or, if that is too large, post a minimal compilable example that demonstrates the problem.

    Bear in mind that a QWindow is probably not what you want/mean.
    http://stackoverflow.com/questions/1...ow-and-qwidget
    Last edited by ChrisW67; 4th April 2014 at 02:36.

  3. #3
    Join Date
    Apr 2014
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Not getting focus on a QWindow on the initial show.

    As you said QWindow is not correct:

    ..._Class(QWidget *parent = 0, Qt::WindowFlags f = Qt::Window) // : QWidget(parent)

    The original definition was:

    ..._Class(QWidget *parent) : QDialog(parent)

    Sorry about the mix-up.

    I'll have to scrub the code and get it approved to submit. It may take a bit.

    Thanks for the quick response.

  4. #4
    Join Date
    Apr 2014
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Not getting focus on a QWindow on the initial show.

    I've attached the scrubbed code in the attached zip file.

    Any help would be appreciated.
    Attached Files Attached Files

  5. #5
    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: Not getting focus on a QWindow on the initial show.

    While the dialog layout is a little broken on my system, I don't have any problem editing the values in the left and right line edits with Qt 4.8.5. The centre line edit is read only so that cannot be edited.

    The dialog relying on absolute positioning, i.e. not using layouts, and your obvious attempts to force focus may be causing issues. Try the attached dialog design. I have added layouts, removed all except the top level size constraint, and removed all non-default mouse tracking or focus settings.

    GUI_Test_Dialog.ui

  6. #6
    Join Date
    Apr 2014
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Not getting focus on a QWindow on the initial show.

    The middle line edit is only editable under certain circumstances - I left widgets in so the full start-up conditions were the same.

    The provided GUI wouldn't open (Designer)/compile (Creator) in my environment (Qt 4.6.3, RHEL 5.5, KDE desktop):

    uic: Error in line 405, column 39 : Unexpected attribute alignment

    I removed alignment="Qt::AlignRight" and built the app.

    The focus issue is still present.

    I commented out the move dialog and forced focus lines. No change.

    Under my environment, the first mouse click just gets focus on the GUI and does not cause any action. The second mouse click, and beyond, function as they should. The original test app, compiled/run under Windows 7 does not have the problem - Linux only.

    From my previous investigations, different Linux window managers process things differently than Windows and also differently among various Linux versions. Thus my hunt to force focus, etc.

    Thank you for your efforts.

Similar Threads

  1. example using Qwindow
    By PstdEr in forum Qt Programming
    Replies: 4
    Last Post: 14th June 2013, 14:31
  2. show new dialog with keeping focus.
    By guri in forum Qt Programming
    Replies: 3
    Last Post: 7th October 2011, 11:04
  3. Show initial widget, best solution?
    By martinn in forum Qt Programming
    Replies: 2
    Last Post: 26th February 2010, 17:49
  4. How to show window without stealing focus?
    By piotr.dobrogost in forum Qt Programming
    Replies: 2
    Last Post: 9th June 2009, 07:26
  5. How to show/draw focus & select at the same time
    By tanminh in forum Qt Programming
    Replies: 2
    Last Post: 6th November 2006, 22:06

Tags for this Thread

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.