Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
No widgets get focus
I'm developing an application for an embedded device, and want to be able to let the user use a USB keyboard to edit text in QLineEdit objects. However, none of my widgets are receiving focus!
Another prototype-style application I made on the same device has no problem with it - the text cursor appears and keyboard entries get treated just like on-screen entries (which use insert(QString)). But in my new application, this just doesn't happen - none of my widgets get focus. I initially had a problem with buttons getting focus (which makes them look weird) so I set all of them to have the Qt::NoFocus policy, but now even when I remove these statements, still nothing gets focus, and I have no idea why.
My main class is a QMainWindow, whose central widget is a QStackedWidget, if that makes any difference.
Anybody got any ideas?
giesbert last edited by
does the parent widgets of the line edit have the noFocus policy set?
I just left them all at their defaults initially. However, even if I make sure they're all set to StrongFocus by doing this in the constructor:
QWidget *p = ui.lineEdit;
} while (p = p->parentWidget());
There's still no joy.
Additionally, I do this after construction-time and printed the objectName of each widget I call setFocusPolicy on, and it definitely goes right up to the top QMainWindow.
A curious thing - I now have another main window that takes over the screen. When I hide it, the widgets in the original window (that did not have focus before) can now all have focus as normal!
Anybody got any idea what's going on here, and how I get back to a focusable state without having to bring up this other window?
Fuzzbender last edited by
Could it be that your original window is for some unknown reason (hard to say why without seeing the whole application code) not active? Try calling setActiveWindow() for it?