Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use qtvirtualkeyboard with qwidget?
Forum Updated to NodeBB v4.3 + New Features

How to use qtvirtualkeyboard with qwidget?

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 6 Posters 3.4k Views 5 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.
  • VevinlongV Offline
    VevinlongV Offline
    Vevinlong
    wrote on last edited by Vevinlong
    #1

    Hi, everyone. I know it supports two alternative integration methods for using the plugin: Desktop or Application. It works well with qml either Desktop or Application by add InputPanel to main.qml. But I have an app implemented by QWidget, I'm wondering if it possible to be integrated to the app implemented by QWidget? Like this(by the way, this is implemented qml):
    0_1525248459115_keyboard test.png

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stevemenke
      wrote on last edited by
      #2

      Did you ever figure this out? I am trying to do the same thing. I have a legacy application written using QWidgets. I want to add the QtVirtualKeyboard plugin. I have it working in Desktop mode. But I want to integrate it into the application as you have shown.

      Thanks,

      Steve

      VevinlongV 1 Reply Last reply
      0
      • S stevemenke

        Did you ever figure this out? I am trying to do the same thing. I have a legacy application written using QWidgets. I want to add the QtVirtualKeyboard plugin. I have it working in Desktop mode. But I want to integrate it into the application as you have shown.

        Thanks,

        Steve

        VevinlongV Offline
        VevinlongV Offline
        Vevinlong
        wrote on last edited by
        #3

        @stevemenke
        Sorry to be so late, I don't login this for a long time. I use a KeyboardPanel which is inherited from QQuichWidget to load a qml file which including the InputPanel. The KeyboardPanel should be a child of mainwindow, so that it couldbe shown over others children widgets. You can contact with me by email: vevinlong@163.com

        <Mainwindow>
        MainWindow::MainWindow(QWidget *parent)
        {
            ...
            m_pKeyboardPanel = KeyboardPanel::getInstance();
            m_pKeyboardPanel->setSource(QUrl(QStringLiteral("qrc:/inputpanel.qml")));
            m_pKeyboardPanel->setParent(this);
            ...
        }
        
        //you need install filter for every lineedit which needs keyboard
        bool MainWindow::eventFilter(QObject* watched, QEvent* event)
        {
            ...
            m_pKeyboardPanel->setNewPos(transformPoint(edit, getCurrentPage()), edit, getCurrentPage());
            ...
        }
        
        <KeyboardPanel >
        
        class KeyboardPanel : public QQuickWidget
        {
            Q_OBJECT
        public:
            static KeyboardPanel* getInstance();
            static QObject* qobject_singletontype_provider(QQmlEngine* engine, QJSEngine* scriptEngine);
            //set the KeyboardPanel shown pos of the page
            void setNewPos(const QPoint& point, QWidget* widget, QWidget* currentPage = nullptr);
            Q_INVOKABLE void hideInput();
        signals:
            
        public slots:
            
        private:
            explicit KeyboardPanel(QWidget* parent = nullptr);
            void setSmallKeyboardPos(const QPoint& point, const QWidget* widget);
            int checkXIsOutOfRange(int x);
            int checkYIsOutOfRange(int y);
            void setFullKeyboardInputPos(const QPoint& point, const QWidget* widget);
        private:
            static KeyboardPanel* ms_pSingleton;
            QWidget* m_pCurrentPage = nullptr;           //the page which it uses the KeyboardPanel 
            int m_movedHeight = 0;
        };
        

        Registe KeyboardPanel to qml

        qmlRegisterSingletonType<KeyboardPanel>("CM780.KeyboardPanel", 1, 0, "KeyboardPanel", qobject_singletontype_provider);
        
        <inputpanel.qml>
        
        import QtQuick 2.7
        import QtQuick.Window 2.0
        import QtQuick.VirtualKeyboard 2.0
        import QtQuick.VirtualKeyboard.Settings 2.0
        import YourApp.KeyboardPanel 1.0
        
        Rectangle {
            id:root
            color: "#eeeeee"
            property var inputMethodHints : InputContext.inputMethodHints;
            
            TextInput{
                anchors.fill: parent
                horizontalAlignment: TextInput.AlignLeft
                verticalAlignment: TextInput.AlignTop
                visible: ((InputContext.inputMethodHints & Qt.ImhDigitsOnly) ||
                          (InputContext.inputMethodHints & Qt.ImhFormattedNumbersOnly)) ? false : true
                readOnly: true
                cursorVisible: false
            }
            
            InputPanel {
                signal closeKeyBoard();
                property int pressKey: -1
                property bool inputpanelVisible: Qt.inputMethod.visible
                
                id: inputPanel
                y:root.height-height 
                width: ((InputContext.inputMethodHints & Qt.ImhDigitsOnly) ||
                        (InputContext.inputMethodHints & Qt.ImhFormattedNumbersOnly)) ? 370 : root.width
                
                states: State {
                    name: "visible"
                    when: inputPanel.active
                    PropertyChanges {
                        target: inputPanel
                        y: root.height - inputPanel.height
                    }
                }
                 
                transitions: Transition {
                    from: ""
                    to: "visible"
                    reversible: true
                    ParallelAnimation {
                        NumberAnimation {
                            properties: "y"
                            duration: 250
                            easing.type: Easing.InOutQuad
                        }
                    }
                }
                
                onInputpanelVisibleChanged: {
                    if (Qt.Key_Escape == pressKey
                            || Qt.Key_Return == pressKey)
                    {
                        if (!inputpanelVisible)
                        {
                            closeKeyBoard()
                        }
                    }
                }
            }
            
            onInputMethodHintsChanged: {
                inputPanel.closeKeyBoard()
            }
            
            Connections{
                target: inputPanel  
                onCloseKeyBoard:{
                    KeyboardPanel.hideInput()
                    inputPanel.pressKey = -1
                }
            }
        }
        
        
        1 Reply Last reply
        4
        • P Offline
          P Offline
          Paraddi
          wrote on last edited by
          #4

          Couple of questions:

          1. Where to register KeyboardPanel to qml ?
          2. What does "CM780.KeyboardPanel" means
            qmlRegisterSingletonType<KeyboardPanel>("CM780.KeyboardPanel", 1, 0, "KeyboardPanel", qobject_singletontype_provider);
          VevinlongV 1 Reply Last reply
          0
          • P Paraddi

            Couple of questions:

            1. Where to register KeyboardPanel to qml ?
            2. What does "CM780.KeyboardPanel" means
              qmlRegisterSingletonType<KeyboardPanel>("CM780.KeyboardPanel", 1, 0, "KeyboardPanel", qobject_singletontype_provider);
            VevinlongV Offline
            VevinlongV Offline
            Vevinlong
            wrote on last edited by
            #5

            @Paraddi

            1. You can register it at the constructor, or others before you use it. It makes the qml to KNOWN the type of KeyboardPanel
            2. For "CM780.KeyboardPanel", it is just a NAME, so that you can import it in qml, for example, your do like this
            qmlRegisterSingletonType<KeyboardPanel>("YourAppName.KeyboardPanel", 1, 0, "KeyboardPanel", qobject_singletontype_provider);
            

            then you can import it like this:

            import QtQuick 2.7
            import QtQuick.Window 2.0
            import QtQuick.VirtualKeyboard 2.0
            import QtQuick.VirtualKeyboard.Settings 2.0
            
            //you can import it here like the qt quick modules like aboves
            import YourAppName.KeyboardPanel 1.0
            

            Note: for this case, I register it as singleton type, so you can invoke the method by KeyboardPanel.yourMethod()

            1 Reply Last reply
            0
            • P Offline
              P Offline
              priyankar
              wrote on last edited by
              #6

              Hi @Vevinlong
              can you share the code

              1 Reply Last reply
              0
              • R Offline
                R Offline
                rajel052
                wrote on last edited by rajel052
                #7

                how to set input method for QLineEdit in virtual keyboard for widgets

                Erorr : qt.virtualkeyboard: InputContext::sendKeyClick(): no focus to send key click - QGuiApplication::focusWindow() is: QQuickView(0x55cb3cf78130)

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rajel052
                  wrote on last edited by rajel052
                  #8

                  Hello @SGaist please help me

                  how to set input method for QLineEdit in virtual keyboard for widgets

                  Erorr : qt.virtualkeyboard: InputContext::sendKeyClick(): no focus to send key click - QGuiApplication::focusWindow() is: QQuickView(0x55cb3cf78130)

                  SGaistS 1 Reply Last reply
                  0
                  • R rajel052

                    Hello @SGaist please help me

                    how to set input method for QLineEdit in virtual keyboard for widgets

                    Erorr : qt.virtualkeyboard: InputContext::sendKeyClick(): no focus to send key click - QGuiApplication::focusWindow() is: QQuickView(0x55cb3cf78130)

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @rajel052 this thread shows how.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      rajel052
                      wrote on last edited by
                      #10

                      @SGaist i am attach the virtual keybord with widgets using :

                      QQuickView *view = new QQuickView();
                      QWidget *container = QWidget::createWindowContainer(view, ui->verticalLayoutWidget);
                      container->setMinimumSize(240, 320);
                      container->setMaximumSize(240, 320);

                       //container->setAttribute(Qt::WA_AcceptTouchEvents);
                       //container->setAttribute(Qt::WA_InputMethodEnabled, true);
                       container->setAttribute(Qt::WA_AcceptTouchEvents);
                       container->setFocusPolicy(Qt::NoFocus);
                       //container->setInputMethodHints(inputMethodHints() | Qt::InputMethodHint::ImhDigitsOnly);
                       view->setSource(QUrl("qrc:/main.qml")); // Fetch this url by right clicking on your resource file.
                      

                      // view->setSource();

                       ui->verticalLayout->addWidget(container);
                      

                      then virtual keyboard attatched with widgets but when i write in QLine edit it throw following error :
                      qt.virtualkeyboard: InputContext::sendKeyClick(): no focus to send key click - QGuiApplication::focusWindow() is: QQuickView(0x55cb3cf78130)

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Why are you using a QQuickView if you want to use QLineEdit ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          rajel052
                          wrote on last edited by
                          #12

                          Hii, @SGaist
                          i am using QQuickView , because i want to attatch virtual keyboard on screen

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            There's no need for a QQuickView to use Qt VirtualKeyboard.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            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