I suggest to use the Qt::mightBeRichText function.
As the official Qt documentation states:
Returns
trueif the string text is likely to be rich text; otherwise returnsfalse.
Although it might detect if it is rich text, in my opinion it's an accurate approach.