Qt的painter.drawtext位置问题
分别调用了drawtext和drawPixmap
painter.drawPixmap(itemX*widthScale/scaleImgToItem,
itemY*heightScale/scaleImgToItem,
m_image[i]->boundingRect().width()/backgroundItem->boundingRect().width()*pm.width(),
m_image[i]->boundingRect().height()/backgroundItem->boundingRect().height()*pm.height(),
m_image[i]->pixmap());
painter.drawText(itemX*widthScale/scaleImgToItem,itemY*heightScale/scaleImgToItem,texts.at(k));
输出如下
img itemX = 1141.53
img itemY = 698.182
img itemX*widthScale/scaleImgToItem = 711.971
img itemY*heightScale/scaleImgToItem = 464.487
text itemX = 1142.3
text itemY = 686.59
text itemX*widthScale/scaleImgToItem = 712.455
text itemY*heightScale/scaleImgToItem = 456.775
预览的图上的位置
实际出来的图上的位置
是什么导致我的drawtext位置偏移这么远。
新增painter设置代码
QPainter painter(&pm);
//这是图片和文字共用的
painter.rotate(angle);
painter.setFont(font);
painter.setPen(static_cast<MyQgraphicsTextItem *>(res.at(i))->getColor()); //这三行是文字独有的设置,如果angle=0那么没有偏移,angle有任何角度就会发生偏移,之前是没有这个问题的,应该是改了背景的boundingrect出现的现在的问题。
m_rect=QRectF(0,0,w,h); //背景的boundingrect用这一行文字打印就有问题
m_rect=QRectF(-w/2,-h/2,w,h);//用这一行文字就没问题,但是图片部分又会有偏移问题。