Hi everyone, I'm stuck with trying to draw a custom cursor, let's say it is a "|", in a certain position that depends on cursor position and size. Here what I am trying to obtain: I want to have this "|" exactly of the same dimension and same position of the normal blinking cursor. The visual appearance of the blinking cursor changes with the actual font size, but the rectangle in with it is placed not, so I cannot simply take the top() and botto() of the rectangle and use them as coordinates.

I tried to use labels and somehow it is acceptable when in the same line there are characters with different size but same (or similar) font (see figureS):
Schermata del 2020-04-19 16-38-09.png
Schermata del 2020-04-19 16-38-24.png
Schermata del 2020-04-19 16-38-53.png

Problems come when in the same line different font families are used: for example the following images include some characters with "Purisa" font:
Schermata del 2020-04-19 16-42-40.png
Schermata del 2020-04-19 16-43-12.png

Here there is the code I used for drawing that labels:
Qt Code:
  1. static double minsize=1000;
  2. // Obtain size of original cursor
  3. const QRect qRect = this->cursorRect();
  4. int x=qRect.height();
  5.  
  6. // Obtain size of current font
  7. QFont font=this->font();
  8. font.setPointSize(this->fontPointSize());
  9. QFontMetrics fm(font);
  10. int y=fm.height();
  11.  
  12. //Correction for small characters
  13. minsize= y<minsize? y:minsize;
  14.  
  15. //Top edge where to start drawing the cursor
  16. int ty=qRect.top()+(x-y)/1.18-minsize/7.0;
  17.  
  18. labelName->show();
  19. labelCursor->show();
  20.  
  21. labelCursor->move(qRect.topLeft().x()-1, ty);
  22. labelName->move(qRect.topLeft().x()+5, ty);
To copy to clipboard, switch view to plain text mode 

There must be something more "plain" I can do, insted of that magic parameters I found after trying.

I also tried to start drawing the label from a position obtained like:
Qt Code:
  1. ty=qRect.bottom()-fm.height();
To copy to clipboard, switch view to plain text mode 
but it's worse than the previous solution.

Hoping someone can help,
kind regards to all.