Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt Quick Dialog focus not work ?
Forum Updated to NodeBB v4.3 + New Features

Qt Quick Dialog focus not work ?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
12 Posts 4 Posters 5.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sardar
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @sardar Dialog doesnot have focus property.
      http://doc.qt.io/qt-5/qml-qtquick-dialogs-dialog-members.html

      If 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.

      157

      1 Reply Last reply
      1
      • S Offline
        S Offline
        sardar
        wrote on last edited by
        #3

        thanks

        Dialog Inherits from popup and popup have focus property. in Gallery example in Qt 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
            }
        
        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          What is popup ? Can you point out that QML type ?

          157

          1 Reply Last reply
          1
          • S Offline
            S Offline
            sardar
            wrote on last edited by sardar
            #5

            Dialog is part of Qt Quick Controls 2.1 added in Qt 5.8. you can see in doc.

            Dialog QML Type
            Popup QML Type

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              @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 the Dialog ?
              Can you try using ApplicationWindow ? 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?

              157

              1 Reply Last reply
              1
              • S Offline
                S Offline
                sardar
                wrote on last edited by
                #7

                thanks for your answer.

                i use Qt samples in SDK, Gallery sample.
                yes, Dialog use in ApplicationWindow.

                1 Reply Last reply
                0
                • p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

                  @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 the Dialog.

                  157

                  1 Reply Last reply
                  1
                  • jpnurmiJ Offline
                    jpnurmiJ Offline
                    jpnurmi
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    2
                    • Z Offline
                      Z Offline
                      Zametuppa
                      wrote on last edited by
                      #10

                      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.

                      jpnurmiJ 1 Reply Last reply
                      0
                      • Z Zametuppa

                        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.

                        jpnurmiJ Offline
                        jpnurmiJ Offline
                        jpnurmi
                        wrote on last edited by
                        #11

                        @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.

                        Z 1 Reply Last reply
                        0
                        • jpnurmiJ jpnurmi

                          @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.

                          Z Offline
                          Z Offline
                          Zametuppa
                          wrote on last edited by
                          #12

                          @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.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved