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

SpinBox does not respect its focusPolicy

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.14.2
    • Fix Version/s: None
    • Component/s: Quick: Controls 2
    • Labels:
      None
    • Platform/s:
      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

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

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There is 1 open Gerrit change