If you click mouse in an object of QTextEdit, sometimes you need to know its position in the text to set the cursor.

Just apply the function cursorForPosition in the mousePressEvent.

The code is following.

void MyTextEdit::mousePressEvent(QMouseEvent * e)
{
  QTextEdit::mousePressEvent(e);

  mCursor.setPosition(cursorForPosition(e->pos()).position());
}

where variable mCursor is type of QTextCursor and declared in the header.

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>