Reputation: 103
I'm making app on Qt5.11 with text edit functionality by QTextEdit component. It works well on Desktop: user can select and edit text, I can change context menu with my own action — everything is great.
But at android platform it is kind of broken. User can set cursor position by touch, but can't select whole word or range of text. If I set selection programmatically then android keyboard hides. After that if I click on selection then range changers appears as well as strange top panel with disabled "copy", "cut" and "paste" buttons. Moreover if I hold finger several seconds than single "paste" button appear on screen. I don't see any way to hide it, prevent it appearance or add custom buttons.
I have tried QWidgets project, QML Quick project and even "Qt Quick Control 2 - Text Editor" example. There is always the same behavior.
It is look like QTextEdit have all necessary functionality but for some reason it doesn't work properly and there are no control.
The best solution that I have came up with is make transparent MouseArea and handle all touches manually. But is it normal?!
Upvotes: 3
Views: 797
Reputation: 333
The automatic text selection handles seem kind of buggy to me in Qt 5.8 through 5.11. Maybe it is best to simply disable them and then add your own buttons for cut/copy/paste manually. At least, for now, until Qt gets them right in a future release.
From digging around in the guts of the Qt Platform Abstraction code, I found an undocumented environment variable that you can set to disable the text selection handles from appearing. Here's how to do it:
int main(int argc, char *argv[])
{
#ifdef Q_OS_ANDROID
qputenv("QT_QPA_NO_TEXT_HANDLES", "1");
#endif
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Upvotes: 3