OK, this bug is multi-layered. The code above is correct. The problem boils down to a bug in the unstyled portion of <code>Text::shape</code>.

To demonstrate this, go to <code>scoreview.cpp</code> in <code>drawDebugInfo()</code>, the following two lines:
<code>
// p.setPen(Qt::red);
// p.drawRect(e->bbox());
</code>
Uncomment them and change <code>red</code> to <code>magenta</code>. You will then see that the magenta box is always in the correct place with the text and relative to the red x. It is the call to <code>Text::shape</code> that is returning the wrong rectangle. I expect it is also <code>Text::shape</code> that is being called to determine whether a click or double-click should select the text too.

I have not yet studied what needs to be done in <code>Text::shape</code>.