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.
