• 10739阅读
  • 4回复

[提问]qt下字符串对齐问题(排版) [复制链接]

上一主题 下一主题
离线feixiangxtu
 

只看楼主 正序阅读 楼主  发表于: 2011-04-04
Row1:字符串1  字符串2
Row2:字符串3  字符串4

以上4个字符串,分为2行,
如果字符串1和字符串3的字符数不同,如何使行1和行2在结构上对齐
比如:
行1:字符          字符描述
行2:字符字符   字符描述

在c++中 sprintf(pTemp, "%-20s", ' ')可以用这个来处理,就是已20个字符来代表这个字段,不足已空格补齐。
QT下如何处理,谢谢。
离线feixiangxtu

只看该作者 4楼 发表于: 2013-05-27
leftJustified这个函数有人用过吗?好像还是用不了。
离线83888788
只看该作者 3楼 发表于: 2011-04-06
回 2楼(feixiangxtu) 的帖子
加个\把
QString t = s.leftJustified(8, ' \ ');    
离线feixiangxtu

只看该作者 2楼 发表于: 2011-04-06
我直接用空格,不行。
QString t = s.leftJustified(8, ' ');    

不知道大家有没有其他办法,谢谢。
离线83888788
只看该作者 1楼 发表于: 2011-04-05
QString QString::leftJustified ( int width, QChar fill = QLatin1Char( ' ' ), bool truncate = false ) const

Returns a string of size width that contains this string padded by the fill character.
If truncate is false and the size() of the string is more than width, then the returned string is a copy of the string.
eg.
     QString s = "apple";
     QString t = s.leftJustified(8, '.');    // t == "apple..."

If truncate is true and the size() of the string is more than width, then any characters in a copy of the string after position width are removed, and the copy is returned.
eg.
     QString str = "Pineapple";
     str = str.leftJustified(5, '.', true);    // str == "Pinea"



这个是qt assistant里面的,只是一个思路 ,里面可能有更好的方法

[ 此帖被83888788在2011-04-05 01:21重新编辑 ]
快速回复
限100 字节
 
上一个 下一个