Solved Sequence of show() and setFocus()
-
Hi
Is it correct that show() on a widget does not also move the Focus to it?
If yes, I have to set the Focus manually with setFocus().
Does the sequence of these need to follow a rule?
Can I set Focus on a widget that is not yet shown or is the other way round correct?I need to send keys to widgets (I'm using QApplication::sendEvent) and make sure they go there.
Thanks
McL -
@McLion
firstshow()
thensetFocus()
Invisible and disabled widgets can't receive focus and thus no input events. -
@raven-worx
OK, thanks ... that's actually what I was thinking.
However, the question came up because I read here: http://doc.qt.io/qt-4.8/focus.html
At the bottom it says:
... call QWidget::setFocus() on the widget which should receive focus before you call QWidget::show() it.
which then would not make sense ... or do I mix some things here? -
@McLion said in Sequence of show() and setFocus():
At the bottom it says:
... call QWidget::setFocus() on the widget which should receive focus before you call QWidget::show() it.
which then would not make sense ... or do I mix some things here?If you leave out the first part of the sentence it indeed is contrary to what i said ;)
What happens is that every window (top-level) QWidget stores it's focus widget to restore it upon show/window-activation.
So when there has never been a focus before, and you set it on a widget which is already a (grand-)child of the window before it is shown, the window stores it and then restores it when it is shown.But still it wouldn't receive input event, because it's not visible.
-
@raven-worx
Thanks for the 'clear-up'. -
... where have the tools gone to set as solved ?
-
@McLion said in Sequence of show() and setFocus():
... where have the tools gone to set as solved ?
a bit hidden:
"TOPIC TOOLS" in the very bottom right -> select "Ask a question"
Then open the menu up again and the "mark as solved" option is there -
@raven-worx said in Sequence of show() and setFocus():
@McLion said in Sequence of show() and setFocus():
... where have the tools gone to set as solved ?
a bit hidden:
"TOPIC TOOLS" in the very bottom right -> select "Ask a question"
Then open the menu up again and the "mark as solved" option is thereJeeez ... who designed this !?!
-
@McLion said in Sequence of show() and setFocus():
Jeeez ... who designed this !?!
People that wanted to make forum software that could be used with other use cases.
Sadly, here we always mean it as a Question but its not default.
So why not remove it?
Well when you start to customize something as big as Qt forum then you get heaps of issue upgrading it to a newer version to get security patches.
Hence it was chosen to use the software as plain as possible.
So while not perfect for our use case, the drawbacks is outweighed by huge factor by the benefit of not
having to spend weeks to see if the old adjustments still works.
So that is why :)