qt: Fix richtext detection hang issue on very old Qt versions

Alternative implementation. Thanks to @awoland for the original.
Fixes #3486.
Merge pull request #3577

17b409b qt: Fix richtext detection hang issue on very old Qt versions (Wladimir J. van der Laan)