Unsolved Qt Quick Dialog focus not work ?
-
hi
when i open dialog and set focus = true , focus not move to dialog and stay in main page and TAB key not work until clicked in one child in dialog.
how can auto move focus to child when dialog opened ? -
@sardar
Dialog
doesnot havefocus
property.
http://doc.qt.io/qt-5/qml-qtquick-dialogs-dialog-members.htmlIf you are trying to bring focus to one of the Item inside that
Dialog
then you can explicitly set focus by setting it to true for that item. -
thanks
Dialog
Inherits frompopup
and popup havefocus
property. in Gallery example inQt 5.8
use focus property in Dialog but it not work.sample code in SDK samples :
Dialog { id: settingsDialog x: Math.round((window.width - width) / 2) y: Math.round(window.height / 6) width: Math.round(Math.min(window.width, window.height) / 3 * 2) height: settingsColumn.implicitHeight + topPadding + bottomPadding modal: true focus: true standardButtons: Dialog.Ok | Dialog.Cancel }
-
What is
popup
? Can you point out that QML type ? -
Dialog
is part ofQt Quick Controls 2.1
added in Qt 5.8. you can see in doc. -
@sardar Well I was not aware of the unreleased version. You're right. It should work.
focus
property is meant for that. Btw. what is the root element from where you launch theDialog
?
Can you try usingApplicationWindow
? As per the the docs:In order to ensure that a popup is displayed above other items in the scene, it is recommended to use ApplicationWindow.
So perhaps the newly opened
Dialog
would get the focus automatically? -
thanks for your answer.
i use Qt samples in SDK, Gallery sample.
yes, Dialog use in ApplicationWindow. -
@sardar In your first post you said you have a child in the
Dialog
. You should also try setting focus to that particular child too once you open theDialog
. -
Looks like a regression caused by another focus-related fix. We'll fix this right away. As a temporary workaround, you can do for example:
Button { onClicked: { dialog.open() dialog.forceActiveFocus() } }
Sorry for the inconvenience.
-
Any news on this ? On this day, it's still not working.
I want to make a Dialog that is a serial shell. In this dialog I have one textArea to display the serial frames received and sent and one textInput for writing the frames I want to send. The problem is that when I type my frame and want to send it by pressing Enter, it is also quitting the dialog as it is pressing on the "Close" button.
I can't figure how to force keyboard focus only on the textInput and not trigger the reject() signal of the dialog when pressing Enter. I tried changing the focus variable but of course, it can not "assign to non-existent property" for the reasons invoked above in this thread (temporary regression). I tried the forceActiveFocus() command but it says that forceActiveFocus is not a function (sic)... I tried to catch the key pressed event but it says "Could not attach Keys property to:" on any object.Here is a curated snippet :
import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.1 import QtQuick.Dialogs 1.2 Dialog { property alias serialExchange: serialExchange id: serialShellRoot title: qsTr("Serial shell") + translator.emptyString modality: Qt.NonModal standardButtons: StandardButton.Close | StandardButton.Reset height: 480 width: 640 ColumnLayout { anchors.fill: parent Rectangle { Layout.fillHeight: true Layout.fillWidth: true border { color: "black" width: 1 } Flickable { anchors.fill: parent TextArea.flickable: TextArea { id: serialExchange wrapMode: TextEdit.WrapAnywhere textFormat: Text.RichText readOnly: true selectByMouse: true font.family: "Courier New" font.pixelSize: 18 color: "white" background: Rectangle { color: "black" } } ScrollBar.vertical: ScrollBar { } } } Rectangle { Layout.fillWidth: true Layout.preferredHeight: 24 border { color: "black" width: 1 } TextInput { id: serialPrompt anchors.fill: parent padding: 5 selectByMouse: true font.family: "Courier New" focus: true onAccepted: { console.log(this.text); } } } } onReset: { serialExchange.remove(0, serialExchange.length); } }
This code is located in a separate SerialShell.qml file and is called from the main.qml file which is an ApplicationWindow.
Any idea about this particular problem (probably) related to some regressions in the dialog code ?
Sorry if this is not the good place for posting this. -
@Zametuppa You are using the Dialog type from QtQuick.Dialogs 1.2, so this is a different issue than the original poster had with the Dialog type from QtQuick.Controls 2.0. The difference between the two Dialog types is that the former is a top-level window on platforms that support multiple top-level windows, whereas the latter is not a top-level window.
-
@jpnurmi Sorry for this, you are right. I haven't made the switch to Qt5.8 and was looking at the wrong documentation anyway. Because some other objects have a Qt Quick and Qt Quick 2 documentation and I use Qt Quick 2, I automatically assumed that I should look at the Qt Quick 2 documentation for the Dialog. Thank you.