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

Alternative implementation. Thanks to @awoland for the original.
Fixes #3486.