hi,

i am trying to port over some legacy wxwidgets code to Qt5 and am running into problems. Basically, there is one textbox that contains text elements. Aligned next to the textbox there is an empty widget used for custom drawing. The custom drawings must now be aligned with the elements in the textbox next to it. elements may span an arbitrary amount of linebreaks, but i cant even get it to work with one line. To make things easier, i set a mono-space font.

The problem is now that i cant get the textlines aligned with my drawing on the widget.


There seem to be two issues:


1) at the beginning of the documents, there seems to be some sort of paragraph-break, ie some pixel lines of extra-empty space.

2) the line height of a text line returned by QFontMetric(font()).height() appears to be off by a little, or there is some linespacing i dont see.


this picture illustrates the two points:

https://i.imgur.com/Q1uqK5b.png


code used for inserting the text line in to the QPlainTextEdit:

Qt Code:
  1. for(auto vil : items)
  2. {
  3. cur.insertBlock();
  4. cur.insertText("testesttest");
  5. cur.block().setUserData(...);
  6. }
To copy to clipboard, switch view to plain text mode 


code used for drawing in the empty widget:

Qt Code:
  1. for (int i = 0; i < lines; i++)
  2. p->drawLine(width() - 5 - ((i % 2) ? 3 : 0), i*LineHeight(),
  3. width() - 5 - ((i % 2) ? 3 : 0), (i + 1)*LineHeight());
  4.  
  5. int LineHeight()
  6. {
  7. return QFontMetrics(font()).height();
  8. }
To copy to clipboard, switch view to plain text mode 



help is appreciated.