简体   繁体   English

QPainter无法正确绘制文本

[英]QPainter not drawing text properly

I am not able to draw path using QPainter drawText() method 我无法使用QPainter drawText()方法绘制路径

QString Path = "/home/User"
QPainter *painter    
QRectF centerRect = QRectF (textX,centerY + m_bounds.height()*0.15, fm.width(Path),fm.height());
painter->drawText(centerRect,Path,QTextOption(Qt::AlignCenter | Qt::AlignHCenter  ));

In windows its drawing the text but on ubunthu Linux its showing only /home 在Windows中,其绘制文本,但在Ubuntu Linux上,其仅显示/ home

QFontMetrics fm = painter->fontMetrics();

qreal centerY = ( m_bounds.height()  -  fm.height() -10  )/2;
qreal textX = 8;

QRectF centerRect = QRectF (textX,centerY + m_bounds.height()*0.15, fm.width(m_folderPath),fm.height());
painter->drawText(centerRect,m_folderPath,QTextOption(Qt::AlignCenter | Qt::AlignHCenter  ));

fm.width(m_folderPath) 

shows differnet value for /home/user and /homeuser4 显示/ home / user和/ homeuser4的differnet值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM