PDA

View Full Version : Not getting focus on a QWindow on the initial show.



TonyGC
3rd April 2014, 17:36
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

ChrisW67
3rd April 2014, 20:57
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/17860604/what-is-the-difference-between-a-qwindow-and-qwidget

TonyGC
4th April 2014, 13:29
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.

TonyGC
7th April 2014, 21:31
I've attached the scrubbed code in the attached zip file.

Any help would be appreciated.

ChrisW67
8th April 2014, 03:41
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.

10274

TonyGC
8th April 2014, 13:41
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.