I want to align text as follow on a QLabel:
name : value
more : other value
longer name : value
It is easily done as follow
QString str;
str += "name\t\t: value\n";
str += "more\t\t: other value\n"
str += "longer name\t: value"
The question is, if I do not know the string pairs beforehand, is there a way in Qt to determine how many \t
-chars must each string get so that they align on the :
(if tabs are the only option)?
I can't use QString::arg() since the text is displayed on a GUI using non-constant-width-text. The issue here is that if I count the number of chars and set the fieldWidth the :
does not align since the width of each char is not the same (changing the font is not an option)
I have tried some logic to count and then 'guess' the number of tabs to insert, which works in general but there might be some corner cases where it might not work.
I can also not make use of any other widgets since the code has only access to the one QLabel*
that it must update.
setw
instead of tabs (would need to pipe it into a stringstream and then extracting the string from the stream) – 463035818_is_not_a_number