Solved How do I set a window to get focus when the program starts?
-
Using this QWidget::setFocus() function is invalid.
-
@mirro said in How do I set a window to get focus when the program starts?:
function is invalid
How is it invalid?
A window get automatically focus when the app starts.
Or do you actually mean that you want a specific widget to have focus? This can be done in Designer already.
Take a look at https://doc.qt.io/qt-5/focus.html, https://doc.qt.io/qt-5/qwidget.html#setTabOrder -
@mirro said in How do I set a window to get focus when the program starts?:
function is invalid
How is it invalid?
A window get automatically focus when the app starts.
Or do you actually mean that you want a specific widget to have focus? This can be done in Designer already.
Take a look at https://doc.qt.io/qt-5/focus.html, https://doc.qt.io/qt-5/qwidget.html#setTabOrder -
@mirro said in How do I set a window to get focus when the program starts?:
Using this QWidget::setFocus() function is invalid.
Show the actual line of code where you use it, and what method you are inside when you do so.
Follow what @jsulm has suggested first. However, I have a dim recollection: depending on your situation, it may be that
setFocus()
doesn't do anything if called too early (e.g. in a contstructor). You might need to override widget'sshowEvent()
, or do it frominstallEventFilter()
, so that you only set focus once the widget becomes visible. Not sure about this, but may be required. -
@jsulm Once the layout is set up, the setFocus invocation is feasible
-
@mirro said in How do I set a window to get focus when the program starts?:
Once the layout is set up, the setFocus invocation is feasible
And what is now the problem?