Well... I waited for a couple of weeks but no-one answered...

I found out a work-around... but maybe someone can provide better solutions! Or at least any documentation about that topic?

Qt Code:
  1. QPoint myPos = this->mapFromGlobal(mousePosition); // convert coordinates of the mouse click
  2.  
  3. if((alignment() &= Qt::AlignLeft) == Qt::AlignLeft) //when left alignment
  4. {
  5. int temp = cursorPositionAt(myPos); //use the easy way
  6. setCursorPosition(temp);
  7. return;
  8. }
  9. //cursorPositionAt works only for left or justified alignment,
  10. //with other alignment it estimate always believing it is left alignment.
  11. //deplacing the point of click is a workaround to this lack
  12. QFontMetrics fm = fontMetrics();
  13. int textWidth = fm.boundingRect(text()).width();
  14.  
  15. setCursorPosition(0); //set at 0 to get the cursorRect() at the right place
  16.  
  17. int marginWidth = cursorRect().right();
  18. int rePosition = width();
  19. if((alignment() &= Qt::AlignRight) == Qt::AlignRight)
  20. {
  21. rePosition = rePosition - textWidth + marginWidth;
  22. }
  23. else //center alignment
  24. {
  25. rePosition = rePosition / 2;
  26. rePosition = rePosition - (textWidth / 2) + marginWidth;
  27. }
  28.  
  29. myPos.setX(myPos.x() - rePosition);
  30. int temp = cursorPositionAt(myPos);
  31. setCursorPosition(temp);
To copy to clipboard, switch view to plain text mode