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

QQuickWidget breaks Tab focus chain

    XMLWordPrintable

Details

    • 996c6d452702162e909285b5be9a831290cff1c9

    Description

      Consider QQuickWidget that displays a QML scene with multiple items that get focus one after another on Tab press. When such widget is a part of GUI with multiple other widgets that accept focus on Tab press, Tab press always switches focus between the widgets, and does not go inside the Tab focus chain of the QML scene displayed inside the QQuickWidget.

      Example:

      The QML scene shown in QQuickWidget consists of three rectangles enclosed one into another. The one having focus is red, two others are green. A press on Tab switches focus between them.

      Now if you uncomment the commented line inside main.cpp, there will be two such widgets one next to another, showing the same QML scene each. Now a press on Tab only switches between the widgets, but not between the items inside each of the QML scenes.

      // Example.qml
      import QtQuick 2.4
      
      Rectangle {
      
          width: 50
          height: 50
          activeFocusOnTab: true
          color: activeFocus ? "green" : "red"
      
          Rectangle {
              anchors.fill: parent
              anchors.margins: 10
              focus: true
              activeFocusOnTab: true
              color: activeFocus ? "green" : "red"
      
              Rectangle {
                  anchors.fill: parent
                  anchors.margins: 10
                  focus: true
                  activeFocusOnTab: true
                  color: activeFocus ? "green" : "red"
              }
          }
      }
      
      // main.cpp
      
      #include <QApplication>
      #include <QQuickWidget>
      #include <QFrame>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
          QQuickWidget w1(QUrl("qrc:/Example.qml"));
          QQuickWidget w2(QUrl("qrc:/Example.qml"));
          QFrame *frame = new QFrame();
          QVBoxLayout *layout = new QVBoxLayout(frame);
          layout->addWidget(&w1);
      
          // Try to uncomment the next line and see how the focus
          // behaviour changes.
          // layout->addWidget(&w2); 
      
          frame->show();
          return app.exec();
      }
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              andysh Andy Shaw
              birdofprey Sergey Pogodin
              Votes:
              5 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes