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. TextField and keyboard on Android
Forum Updated to NodeBB v4.3 + New Features

TextField and keyboard on Android

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlandroidqt 5.6.0
16 Posts 4 Posters 10.2k Views 3 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.
  • SkroopaS Offline
    SkroopaS Offline
    Skroopa
    wrote on last edited by
    #6

    Thanks for your help, but... Keyboard isn't visible. I can't understand, where is the problem, because program absolutely simple.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #7

      The following works for me on Android 4.3. Does it work for you?

      main.cpp

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
      
          return app.exec();
      }
      

      main.qml

      import QtQuick 2.6
      import QtQuick.Controls 1.5
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Rectangle {
              color: "#00000000"
              anchors.fill: contentItem
      
              TextField {
                  anchors.centerIn: parent
              }
          }
      
          Button {
              anchors.bottom: contentItem.bottom
              text: "Exit"
              onClicked: Qt.quit()
          }
      }
      
      SkroopaS 1 Reply Last reply
      0
      • ? A Former User

        The following works for me on Android 4.3. Does it work for you?

        main.cpp

        #include <QGuiApplication>
        #include <QQmlApplicationEngine>
        
        int main(int argc, char *argv[])
        {
            QGuiApplication app(argc, argv);
        
            QQmlApplicationEngine engine;
            engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
        
            return app.exec();
        }
        

        main.qml

        import QtQuick 2.6
        import QtQuick.Controls 1.5
        
        ApplicationWindow {
            visible: true
            width: 640
            height: 480
            title: qsTr("Hello World")
        
            Rectangle {
                color: "#00000000"
                anchors.fill: contentItem
        
                TextField {
                    anchors.centerIn: parent
                }
            }
        
            Button {
                anchors.bottom: contentItem.bottom
                text: "Exit"
                onClicked: Qt.quit()
            }
        }
        
        SkroopaS Offline
        SkroopaS Offline
        Skroopa
        wrote on last edited by Skroopa
        #8

        @Wieland God bless you, sir! It works,
        but only if you are using ApplicationWindow... It's a bug?
        I think, we found the right path!

        Update:
        The main feature of my application, that QML GUI draws over Android's SurfaceView. Qt don't provide any tools to use Android's MediaCodec-s and I must to use Qt::WA_TranslucentBackground and Qt::WindowStaysOnTopHint flags to achive "layer-cake" like app.
        But if I use this flags, TextField / TextInput doesn't show keyboard anymore ))))):
        Is it possible to show keyboard or I must write my own keyboard widget?

        1 Reply Last reply
        0
        • SkroopaS Offline
          SkroopaS Offline
          Skroopa
          wrote on last edited by Skroopa
          #9

          Simple example:

          #include <QtQuick>
          
          int main(int argc, char *argv[]) {
          
              QGuiApplication a(argc, argv);
          
              QQuickView view;
              view.setSource(QUrl("qrc:/main.qml"));
              view.setFlags(Qt::WindowStaysOnTopHint | static_cast<Qt::WindowFlags>(Qt::WA_TranslucentBackground));
              view.showFullScreen();
          
              QObject::connect(view.rootContext()->engine(), SIGNAL(quit()), QGuiApplication::instance(), SLOT(quit()));
          
              return a.exec();
          }
          

          Setting any flags to QQuickView makes TextField unfocusable and keyboard never shows on Android (not tested on iOS). Is it possible way to solve trouble with keyboard?
          I think, it is very important bug.

          UPDATE
          Also, I tried this:

          view.setFlags(view.flags());
          

          result the same - no keyboard. I'm sure - it's a bug.
          Please, someone, help. Project is stuck.

          ? 1 Reply Last reply
          0
          • SkroopaS Skroopa

            Simple example:

            #include <QtQuick>
            
            int main(int argc, char *argv[]) {
            
                QGuiApplication a(argc, argv);
            
                QQuickView view;
                view.setSource(QUrl("qrc:/main.qml"));
                view.setFlags(Qt::WindowStaysOnTopHint | static_cast<Qt::WindowFlags>(Qt::WA_TranslucentBackground));
                view.showFullScreen();
            
                QObject::connect(view.rootContext()->engine(), SIGNAL(quit()), QGuiApplication::instance(), SLOT(quit()));
            
                return a.exec();
            }
            

            Setting any flags to QQuickView makes TextField unfocusable and keyboard never shows on Android (not tested on iOS). Is it possible way to solve trouble with keyboard?
            I think, it is very important bug.

            UPDATE
            Also, I tried this:

            view.setFlags(view.flags());
            

            result the same - no keyboard. I'm sure - it's a bug.
            Please, someone, help. Project is stuck.

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by A Former User
            #10

            I don't think it's a bug. The Qt::WindowStaysOnTopHint flag forbids the keyboard "window" to come up. Maybe you can work around it by removing this flag everytime before the keyboard shall be shown.

            1 Reply Last reply
            0
            • SkroopaS Offline
              SkroopaS Offline
              Skroopa
              wrote on last edited by Skroopa
              #11

              Okay, after week I found the next strange things of ApplicationWindow, when I set flags: Qt.WindowStaysOnTopHint to it:

              1. ApplicationWindow now is inactive, i.e. ApplicationWindow.active == false. requestActivate() doesn't help - active is false anyway.
              2. ApplicationWindow's activeFocusItem == null.

              There is two reasons, why keyboard doesn't show on Android after touching to TextField.
              Any ideas, how to fix that? Thanks.

              1 Reply Last reply
              0
              • SkroopaS Offline
                SkroopaS Offline
                Skroopa
                wrote on last edited by Skroopa
                #12

                Tried this:

                    QGuiApplication a(argc, argv);
                    QQmlApplicationEngine engine(QUrl(QStringLiteral("qrc:/main.qml")));
                
                    for(int i = 0; i < a.allWindows().size(); i++) {
                        if(a.allWindows()[i]->objectName() == "mainWindow") {
                            a.allWindows()[i]->requestActivate();
                            break;
                        }
                    }
                

                Without results... a.focusWindow() is NULL. Can anyone help to me?
                ApplicationWindow is fullscreen and has width and height equal Screen size.
                Spent for this problem more than 2 weeks - no help in any forum...

                P.S. on Windows OS all works perfectly - window activates and focusWindow() is not NULL (gives me ApplicationWindow_QMLTYPE_73(0x6335590, name="mainWindow"))

                1 Reply Last reply
                0
                • SkroopaS Offline
                  SkroopaS Offline
                  Skroopa
                  wrote on last edited by Skroopa
                  #13

                  Done!

                      for(int i = 0; i < a.allWindows().size(); i++) {
                          if(a.allWindows()[i]->objectName() == "mainWindow") {
                              a.allWindows()[i]->close();
                              a.allWindows()[i]->setFlags(static_cast<Qt::WindowFlags>(a.allWindows()[i]->flags()) | Qt::WindowStaysOnTopHint);
                              a.allWindows()[i]->show();
                              a.allWindows()[i]->showFullScreen();
                              break;
                          }
                      }
                  

                  and keyboard is showing now! Hell, yeah!
                  Also, you must not set any flags to ApplicationWindow in QML code, otherwise keyboard will be hidden.

                  ? 1 Reply Last reply
                  3
                  • SkroopaS Skroopa

                    Done!

                        for(int i = 0; i < a.allWindows().size(); i++) {
                            if(a.allWindows()[i]->objectName() == "mainWindow") {
                                a.allWindows()[i]->close();
                                a.allWindows()[i]->setFlags(static_cast<Qt::WindowFlags>(a.allWindows()[i]->flags()) | Qt::WindowStaysOnTopHint);
                                a.allWindows()[i]->show();
                                a.allWindows()[i]->showFullScreen();
                                break;
                            }
                        }
                    

                    and keyboard is showing now! Hell, yeah!
                    Also, you must not set any flags to ApplicationWindow in QML code, otherwise keyboard will be hidden.

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #14

                    @Skroopa Congrats! Looks like you're the first guy on the planet who found out how this works. Hats off!

                    SkroopaS 1 Reply Last reply
                    1
                    • ? A Former User

                      @Skroopa Congrats! Looks like you're the first guy on the planet who found out how this works. Hats off!

                      SkroopaS Offline
                      SkroopaS Offline
                      Skroopa
                      wrote on last edited by Skroopa
                      #15

                      @Wieland Ha-ha! (:
                      Someone today would be drunk...

                      1 Reply Last reply
                      1
                      • R Offline
                        R Offline
                        RichardLiu
                        wrote on last edited by
                        #16

                        when the window inactive, just raise it

                        onActiveChanged:{
                        if(!rootWin.active){
                        rootWin.raise()
                        console.log("rootWin raise")
                        }
                        }

                        1 Reply Last reply
                        0

                        • Login

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