Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ActiveFocus not changing after Qml Window re activated
Forum Updated to NodeBB v4.3 + New Features

ActiveFocus not changing after Qml Window re activated

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 498 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nando
    wrote on 13 Apr 2020, 11:12 last edited by Nando
    #1

    Hello,
    running on MacOS i have a Window or ApplicationWindow which gets created from C++.

    I think the problem must be how i create the window from C++ because if i run it in plain qml it works fine...

    QQmlApplicationEngine engine; // is a class member declared in .h
    
    vod MainWindow::MyWindow()
    {
        QQmlContext *ctxt = engine.rootContext();
        ctxt->setContextProperty("DatabaseManager", &DatabaseManager::instance());
        qmlRegisterType<SomeType>("my.qmlcomponents", 1, 0, "SomeType");
        connect(&m_engine, SIGNAL(objectCreated(QObject *, const QUrl &)),
                this, SLOT(qmlEngineObjectCreated(QObject *, const QUrl &)));
        engine.load(QUrl("qrc:/qml/EditDialog.qml"));
    }
    
    void MainWindow::qmlEngineObjectCreated(QObject *object, const QUrl &url)
    {
        m_resolverQmlObject = object;  // m_resolverQmlObject is QObject type
    
        QWidget *w = QWidget::createWindowContainer(qobject_cast<QQuickWindow*>(object), this);
        
        qDebug() << "Got EditDialog";
        w->setParent(nullptr); // Without this the Window is not coming up
        w->setWindowModality(Qt::ApplicationModal);
        QQmlEngine::setObjectOwnership(m_resolverQmlObject, QQmlEngine::CppOwnership);
        w->show();
    }
            
    

    Inside the Window i have for example some TextField components.
    Everything works fine. If i click inside a TextField it gets the focus and i can enter text.

    And i see in my (root) Window onActiveFocusItemChanged gets triggered each time i click in another TextField.

    Now if i click outside my application and the app looses focus and the click again into the application Window inside a TextField the TextField gets focus as before but no KeyEvents occur. So if i type the TextField does not show the typed characters.
    Also onActiveFocusItemChanged gets not called anymore.

    Any idea why activeFocusItem isn't updating after the Window lost focus and then got focus again?

    Window {
        onActiveFocusItemChanged: {
            print("activeFocusItem: ", activeFocusItem)
        }
    
         RowLayout {
              anchors.fill: parent
              TextField {
                  id: tf1
                  onFocusChanged: {
                      print("TextField 1 got focus")
                  }
              }
              TextField {
                  id: tf2
                  onFocusChanged: {
                      print("TextField 2 got focus")
                  }
             }
        }
    }
    

    Greetings
    Nando

    1 Reply Last reply
    0

    1/1

    13 Apr 2020, 11:12

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved