Pregunta

Para mi aplicación basada en QML. Me gustaría tener un teclado virtual (QT Enterprise es una burla de este tipo, pero 200 $

Aquí es cómo veo el código:

keypress.h

#ifndef KEYPRESS_H
#define KEYPRESS_H

#include <QObject>

class KeyPress : public QObject
{

    Q_OBJECT

public:
    explicit KeyPress(QObject *parent = 0);

    Q_INVOKABLE void virtKeyPress(const int& Char);

signals:
    void virtKeyPressed(const int& source);

private:
    int vKey;
};

#endif // KEYPRESS_H

keypress.cpp

#include "keypress.h"
#include <QKeyEvent>

KeyPress::KeyPress(QObject *parent) :
    QObject(parent)
{

}

void KeyPress::virtKeyPress(const int &Char){

    vKey = Char;
    QKeyEvent event(QEvent::KeyPress, vKey, Qt::NoModifier);
    // Here I guess I should do somthing like "sendEvent(parent, &event);" or whatever, but nothing seems to work.
    emit virtKeyPressed(vKey);


}

Tengo algunas ideas sobre cómo enlementar esto en solo QML, pero dónde está la diversión en eso.:) Así que me gustaría pedir su orientación sobre el tema. Por cierto, he buscado a través de la información en la web, sin embargo, no se ha encontrado ningún código de trabajo.

¿Fue útil?

Solución

Enviar un evento clave a un objeto QT Quick es como:

QKeyEvent *event = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
QCoreApplication::postEvent (engine->rootObjects().first(), event);

También puede echar un vistazo a ejemplo del panel de entrada .Muestra cómo ingresar texto en widgets mediante un panel de entrada usando solo el puntero y no el teclado.

Otro es VirtualKeyboard .Consulte el código fuente y cámbielo para satisfacer sus necesidades.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top