Calculating sizeHint height for CustomDelegate with WrapAtWordBoundaryOrAnywhere Text
-
Hey,
How do you calculate the required sizeHint for an item where you need to paint a string with QTextOption flags such as WrapAtWordBoundaryOrAnywhere
I cant use fontMetrics since i do not know where exactly the text is going to be cut to the next line.
I tried using QTextDocument and setting the width i need and Getting the size out of it to calculate required height.
But this has some strange behaviour when scrolling through the view where it does not seem to paint the item if its only partially visible.
-
In a similar case, I used QTextDocument in the way you describe: set the width, and get out the height. I don't see why your sizeHint implementation would influence your rendering though?
-
Yeh Andre thats what is puzzling me too. but ill debug it further if that is the way you guys would approach it too.
It seems for some reason that items with multiple lines only half the lines get painted until the entire item is visible. It was not like sizeHint returned incorrect values though cos the item had the correct size. It was just blank at the bottom until i scrolled to get full item visible and it paints itself correctly.
In the paintEvent i did use painter->drawText with textoption flag than use QTextDocument drawContents to not have to recreate QTextDocument inside it again but maybe thats having some strange outcomes. will check further tomorrow and update.