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

Improve default focus handling of QmlView

    XMLWordPrintable

Details

    • 1c21463

    Description

      With default configuration, input items do not get focus / do not work within a QmlView.

      Say you create a minimal qml example:

      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent)
      {
          QDeclarativeView *view = new QDeclarativeView;
          view->setSource(QUrl("test.qml"));
          setCentralWidget(view);
      }
      

      With test.qml being defined as:

      import Qt 4.6
       TextInput{
        width: 200
        height: 200
      }
      

      If you launch this, you can click on the Input, and get a blinking cursor, but you can't type. For this you have to change the focusPolicy:

      view->setFocusPolicy(Qt::ClickFocus);

      This is because QmlView calls

      viewport()->setFocusPolicy(Qt::NoFocus)

      which doesn't seem right. Also the qml viewer does this:

      "canvas->setFocus();"

      which can probably be better achieved by setFocusPolicy(Qt::StrongFocus).

      (Sometimes you also have to explicitly activate the scene afterwards, e.g. following line is also needed in Bauhaus):

      QApplication::sendEvent(myQmlView->scene(), new QEvent(QEvent::WindowActivate));

      Attachments

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

        Activity

          People

            martjone Martin Jones (closed Nokia identity) (Inactive)
            kkohne Kai Köhne
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes