title: QTextBrowser: How to highlight a clicked line
body: <p>In my textbrowser, I've already implemented the mousePress and found the line number when clicked. Now I want to highlight where I clicked i.e., change its background color. I knew line is different with block. Luckily in my text one line is one block. So What I did is to manipulate the block format by cursor, listed as follows:</p>
  
  <pre><code>QTextCursor cur = mytextBrowser-&gt;textCursor();
  QBlockFormat f;
  f.setBackground(Qt::red);
  cur.selection(QTextCursor::BlockUnderCursor);
  cur.setBlockFormat(f);
  cur.setPosition(startPos);//I calculate this startPos before. It's where the cursor should be
  mytextBrowser-&gt;setTextCursor(cur);
  </code></pre>
  
  <p>However, the result is odd. When I first click the text, nothing happened, sometimes maybe selected a word. Then I click again, that previous line and the above line would be highlighted. I don't understand why this happened. Could anyone give me some solutions? Thanks.</p>