Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-88578

SpinBox does not respect its focusPolicy

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.14.2
    • Quick: Controls 2
    • Windows

    Description

      I want to skip a SpinBox in the tab focus chain if it is not editable, but I noticed that it is always included in the tab focus chain, despite setting it's focusPolicy.

      I found that in this case, activeFocusItem is of type QQuickTextInput, so it seems that the focus is still given to it's TextInput

      Edit: I made a simple example showing the issue. See below and/or attachment.
      I also added a gif where I use tab to demo the next in chain focus (and clicked some buttons to show their focusPolicy-usage)

      // Main.qml
      import QtQuick 2.14
      import QtQuick.Window 2.14
      import QtQuick.Layouts 1.14
      import QtQuick.Controls 2.14
      
      Window {
          id: mainWindow
      
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          function getFocusPolicy(intValue) {
              switch (intValue) {
              case Qt.TabFocus:
                  return "TabFocus";
              case Qt.ClickFocus:
                  return "ClickFocus";
              case Qt.StrongFocus:
                  return "StrongFocus";
              case Qt.WheelFocus:
                  return "WheelFocus";
              case Qt.NoFocus:
                  return "NoFocus";
              }
          }
      
          ColumnLayout {
              TestSpinBox {}
              TestButton { }
      
              TestSpinBox { focusPolicy: Qt.StrongFocus }
              TestButton { focusPolicy: Qt.StrongFocus }
      
              TestSpinBox { focusPolicy: Qt.ClickFocus }
              TestButton { focusPolicy: Qt.ClickFocus }
      
              TestSpinBox { focusPolicy: Qt.TabFocus }
              TestButton { focusPolicy: Qt.TabFocus }
      
              TestSpinBox { focusPolicy: Qt.NoFocus }
              TestButton { focusPolicy: Qt.NoFocus }
      
          }
      }
      
      // TestButton.qml
      import QtQuick 2.14
      import QtQuick.Controls 2.14
      
      Button {
          id: testButton
      
          implicitHeight: 24
          implicitWidth: 120
      
          background: Rectangle {
              color: testButton.activeFocus ? "green" : "grey"
          }
      
          text: mainWindow.getFocusPolicy(testButton.focusPolicy)
      }
      
      // TestSpinBox
      import QtQuick 2.14
      import QtQuick.Layouts 1.14
      import QtQuick.Controls 2.14
      
      RowLayout {
          id: testSpinBox
      
          property int focusPolicy: 0
      
          Text {
              text: mainWindow.getFocusPolicy(spinBox.focusPolicy)
          }
      
          SpinBox { id: spinBox; focusPolicy: testSpinBox.focusPolicy }
      }
      

      Attachments

        1. demo bug.gif
          demo bug.gif
          105 kB
        2. main.qml
          1 kB
        3. qtbug88578.zip
          3 kB
        4. TestButton.qml
          0.3 kB
        5. TestSpinBox.qml
          0.3 kB

        Issue Links

          For Gerrit Dashboard: QTBUG-88578
          # Subject Branch Project Status CR V

          Activity

            People

              mitch_curtis Mitch Curtis
              rjmsilf Robert Silfhout
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes