draw a string which fit all the width avaible
Unsolved
General and Desktop
-
Hi,
I would like to draw a string (using QPainter) which use all the width avaible by changing caracter spaces.
For exemple, with string A = "ACGT" and string B = "ACGTATGTAGTAGTAGTAGTAGTAGATTTGTATATTG"+----------------WIDH----------------+ A C G T // string A ACGTATGTAGTAGTAGTAGTAGTAGATTTGTATATTG // string B
Do you think there is a helper function to do that ? With paintText ? QTextOption ? AlignementFlags ?
-
Hi
You can control the space with
http://doc.qt.io/qt-5/qfont.html#setKerning
so if you not require it to be perfect, you can quick make such functionQString StrSample = "TestMe" ; QRect r = QRect(0, 0, 190, 30); QFont font = painter.font(); QFontMetrics fm(font); int tw = fm.width(StrSample); int diff = r.width() - tw; qreal lettersp = font.letterSpacing(); qreal delta = diff / ( StrSample.length() - 1); font.setLetterSpacing(QFont::AbsoluteSpacing, lettersp + delta); painter.setFont(font);
There might be a Qt function that does it but im not stumbled upon it :)