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

你说的曾经没有我的故事 提交于 2021-02-08 04:47:34

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/39436518/how-to-get-the-android-keyboard-to-appear-when-using-qt-for-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!