aarelovich
aarelovich

Reputation: 5566

How to get the android keyboard to appear when using Qt For Android?

I've created a minimal working example of an Input box I'd like to develop using a QGraphicsItem. Here is the code (I'd figure the .h is not necessary):

TestEditor::TestEditor()
{
    text = "";
    boundingBox = QRectF(0,0,200,100);
}

QRectF TestEditor::boundingRect() const{
    return boundingBox;
}

void TestEditor::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){

    painter->setBrush(QBrush(Qt::gray));
    painter->drawRect(boundingBox);
    painter->setBrush(QBrush(Qt::black));
    painter->drawText(boundingBox,text);

}

void TestEditor::keyReleaseEvent(QKeyEvent *event){
    qDebug() << "Aca toy";
    text = text + event->text();
    update();
}

My tester application is simply adding it to a graphics view to test it:

   TestEditor *editor = new TestEditor();
    editor->setText("Algo de texto como para empezar");
    editor->setFlag(QGraphicsItem::ItemAcceptsInputMethod,true);
    editor->setFlag(QGraphicsItem::ItemIsFocusable,true);
    editor->setFlag(QGraphicsItem::ItemIsSelectable,true);
    ui->gvScreen->scene()->addItem(editor);

When I test this on my PC it works fine. When I compile it for android, I get the problem that keyboard doesn't appear so I can't try it out. How can I force the keyboard to appear?

Upvotes: 2

Views: 1791

Answers (1)

aarelovich
aarelovich

Reputation: 5566

Well In case anyone is wondering I've found a way to force the android keyboard to show.

QInputMethod *keyboard = QGuiApplication::inputMethod();
keyboard->show();

I've lost the code where I used it so I don't rembember if QGuiApplication can be called from anywhere. But if it can't you can simply sotre the pointer to the keyboard from your main form/class and pass it as a parameter to any sort of required item or class

Upvotes: 3

Related Questions