qml how to keep focus on TextField - qt

I want to keep focus on TextField. For example i am typing something then tap to button. The focus on TextField is moving to button, that's why keyboard is automatically hiding on Android. I am using Qt 5.9.2. Thanks in advance!

In Qt Quick Controls 2, each control has a focusPolicy property which determines how the control gets focus. The default for controls like Button is Qt.StrongFocus, which means that buttons get focus after being clicked or tabbed into. If you're seeing that a control has focus and you don't want it to, just set its focusPolicy to Qt.NoFocus:
focusPolicy: Qt.NoFocus

Related

combobox qml in QT stay down

I add simple combobox in my qml form but after selection, the button of it stay blue like the mouse stay clicked and I can not select any more after the first click, do you know why?...
ComboBox{
model:["test1","test2"]
}
image upload is not working then here drive link to see what I mean:
https://drive.google.com/open?id=1Un0pOCTbmEu_FeCHDzTYKF8FbV4YTxHR
thank you for your help
Qt 5.10.0 added support for native menus on Windows. This caused a regression in Qt Quick Controls 1 ComboBox. ComboBox did not get notified that the menu popup was closed, so it thought it was still pressed and therefore refused to re-open the popup. The bug (QTBUG-64628) has been fixed in Qt 5.10.1. Try updating.

What Object has Active Focus in QML?

i have a complex GUI with QML but in some situation i lost my focus and i don't know what object has active focus.
Is there any tools or ways to search in QML files and find focused Object?
I use this line to see which item has active focus:
Window {
onActiveFocusItemChanged: print("activeFocusItem", activeFocusItem)
}
This code responds to changes in the activeFocusItem property of Window by printing out the item with active focus. ApplicationWindow from Qt Quick Controls 1 and 2 have the same property since they derive from Window.
To find out how an item got focus, you can set the QT_LOGGING_RULES environment variable to qt.quick.focus = true. This enables logging for Qt's internal focus handling. The output can be a bit tricky to follow though..
Since you're using Qt Quick Controls 2, it's worth noting that each control has a focusPolicy property which determines how the control gets focus. The default for controls like Button is Qt.StrongFocus, which means that buttons get focus after being clicked or tabbed into. If you're seeing that a control has focus and you don't want it to, just set its focusPolicy to Qt.NoFocus:
focusPolicy: Qt.NoFocus

How to make a QLabel turn to be a combobox or edit control, when you clicked this label

It looks like a label normally, once you move the mouse over it, or clicked it, then will turn to be a edit control or combobox likewise.
Use a QStackedWidget. According to the docs, "The QStackedWidget class provides a stack of widgets where only one widget is visible at a time." You can then reimplement QWidget::enterEvent and QWidget::leaveEvent to detect mouse overs and show the appropriate widget.

QML ListView Delegates z-order are always on top of everything else

I have a QML ListView with a custom widget (I call it PayloadOdometerRecord) as a delegate. This PayloadOdometerRecord contains a couple of other custom widgets (TextBox) that when clicked will change state and display a keyboard for user input.
The ListView works correctly until the user clicks one of these TextBox widgets to display the keyboard. The keyboard gets clipped by all of the delegates below the delegate that is displaying the keyboard.
When using this TextBox widget in a non-ListView, it works correctly...the keyboard is fully visible.
Does anyone have any idea why this is happening? My goal is to have a full-screen keyboard that shows up and is not covered by any other components.
Thanks!
Can you show some code? What is the parent of your keyboard component?
Z works only between siblings. The keyboard should be a child of the root element and have a higher z value than the other children of root to make it work.
If there are other components in front of the keyboard, you can try to set the keyboards z-property to a large value (e.g. 1000) → Qt Doc

Setting button focus in a graphcisview

I have placed a few buttons in a Qgraphicsscene, but I don’t know how to navigate to the button from a keyboard.
How would I set the focus to a button from the keyboard?
I assume that you used QGraphicsScene::addWidget() to add the button to the scene? It gives you a proxy object back, QGraphicsProxyWidget *, which inherits QGraphicsItem::setFocus(). But remember that it needs to have set the ItemIsFocusable flag and needs to be visible and active as well.
Additionally (from the setFocus() documentation):
As a result of calling this function, this item will receive a focus in event with focusReason. If another item already has focus, that item will first receive a focus out event indicating that it has lost input focus.

Resources