qt: fix tablet crash. closes #4854.

This backports the relevant parts of:
https://codereview.qt-project.org/#/c/82689/
Merge pull request #4874

21f139b qt: fix tablet crash. closes #4854. (Cory Fields)