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

TextEdit QML element inside widget never get back focus

XMLWordPrintable

      Once TextEdit element lost focus, it can never get back again unless the top level widget lost and get focus again.
      Please see next codes:

      main.cpp
      #include <QApplication>
      #include <QLabel>
      #include <QQuickView>
      #include <QTemporaryFile>
      #include <QVBoxLayout>
      
      const char *src =
              "import QtQuick 2.3\n"
              "Rectangle {\n"
              "    TextEdit {\n"
              "        anchors.fill: parent\n"
              "        text: \"Hello World!\"\n"
              "        focus: true\n"
              "        selectByMouse: true\n"
              "        selectByKeyboard: true\n"
              "    }\n"
              "}\n";
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QTemporaryFile file; file.open(); file.write(src); file.flush();
      
          QWidget w;
          QQuickView *view = new QQuickView;
          view->setSource(QUrl::fromLocalFile(file.fileName()));
          QVBoxLayout *vbox = new QVBoxLayout(&w);
          vbox->addWidget(new QLabel("Label"));
          vbox->addWidget(QWidget::createWindowContainer(view));
      
          w.resize(200, 200);
          w.show();
          return a.exec();
      }
      

      When run this code, the TextEdit accepts keyboard inputs.
      However, once click other place outside of QQuickView, that is, the 'label area', TextEdit never works again even if you click the element again.

      The only method I found to make it work again is to make the top level widget lose focus and get again, for instance, hide and show or select other window and return, etc.

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

            aalpert Alan Alpert
            xylosper Byoung-young Lee
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes