gpt4 book ai didi

c++ - 如何确定 painter.drawPath(QPainterPath) 绘制的元素类型

转载 作者:搜寻专家 更新时间:2023-10-31 01:47:48 24 4
gpt4 key购买 nike

我正在为给定字符绘制字形轮廓,使用:

QString myfname="FreeMono.ttf";
QRawFont *myfont=new QRawFont(myfname,324,QFont::PreferDefaultHinting);
QChar mychars[]={'Q','B'};
int numofchars=3;
quint32 myglyphindexes[3];
int numofglyphs;
myfont->glyphIndexesForChars(mychars,numofchars,myglyphindexes,&numofglyphs);
QPainterPath mypath=myfont->pathForGlyph(myglyphindexes[0]);

我在像素图上使用的这条路径

painter.drawPath(mypath)

我想知道这条路是怎么画的。我的意思是这个大纲包含什么类型的曲线或线条。为此,我尝试了这个:

QPointF mypoints[49];
for(int i=0; i<mypath.elementAt(i); i++)
{
mypoints[i]=mypath.elementAt(i);
}

这给了我点数组。但是这些点如何像使用直线或曲线一样相互连接。我怎么知道?这也是一种正确的方法吗?我需要改进什么?

最佳答案

QPainterPath::elementAt() 返回类型为 QPainterPath::Element 的对象,而不是 QPoint(它定义了一个 QPointF 运算符)。

您可以使用这样的代码:

const QPainterPath::Element &elem = path.elementAt(ii);

// You can use the type enum.
qDebug() << elem.type;

// Or you can use the functions.
if (elem.isCurveTo()) {
qDebug() << "curve";
} else if (elem.isLineTo()) {
qDebug() << "line";
} else if (elem.isMoveTo()) {
qDebug() << "move";
}

关于c++ - 如何确定 painter.drawPath(QPainterPath) 绘制的元素类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18734212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com