I change to contextMenuEvent:

Qt Code:
  1. void MainTextEdit::contextMenuEvent(QContextMenuEvent *event)
  2. {
  3. if (this->textCursor().selectedText().isEmpty() == true) // if nothing selected
  4. {
  5. QTextCursor cursor = cursorForPosition(event->pos());
  6. cursor.select(QTextCursor::WordUnderCursor);
  7. if (!cursor.selectedText().isEmpty())
  8. {
  9. QString strText = cursor.selectedText();
  10. int iPos = cursor.position() - cursor.block().position(); // cursor.positionInBlock()
  11.  
  12. cursor.select(QTextCursor::BlockUnderCursor);
  13. QString strBlock = cursor.selectedText().trimmed();
  14. QStringList strlBlock = strBlock.split(" ");
  15.  
  16. QString strWord = strlBlock[1];
  17.  
  18. // channel
  19. if (strText.at(0) == '#')
  20. {
  21. ...
  22. QMenu *menu = new QMenu(strChannel);
  23. ...
  24. menu->popup(event->globalPos());
  25. return;
  26. }
  27.  
  28. // nick
  29. if ((iPos > 11) && (iPos < 11+2+strWord.length()))
  30. {
  31. ...
  32. QMenu *menu = new QMenu(strNick);
  33. ...
  34. menu->popup(event->globalPos());
  35. return;
  36. }
  37. }
  38. }
  39.  
  40. QTextEdit::contextMenuEvent(event);
  41. }
To copy to clipboard, switch view to plain text mode 

but still sometimes vertical scroll bar stops ...