qt: fix tablet crash. closes #4854.

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