请问为什么在WINDOWS上通过QT绘制的字体的坐标不对?
核心问题有三(基于QT 4.6):
一:QFont的函数setPixelSize与setPointSize有什么区别?
比如我想将字体大小设置为100*100,需调哪个函数?
二:我想在指点坐标点绘制字符串,设置字体大小为100*100,调用DrawText
比如qPaint.drawText(0,200,gbk_string);
qPaint.drawRect(0,100,500,100);为什么字体为跑出矩形框?是不是什么没搞对?
三:我要将生成的数据保存为图片,QT帮助文档里说可以保存为JPG的,为什么JPG文件没有生成?
下面是代码:我是在VS2005中测试的
#include "stdafx.h"#include <QCoreApplication.h>#include <QApplication.h>#include <QPixmap.h>#include <QPainter.h>#include <iostream>#include "qtextcodec.h "#include "qobject.h"using namespace std;#ifdef _DEBUG#pragma comment(lib,"QtCored4.lib")#pragma comment(lib,"QtGuid4.lib")#else#pragma comment(lib,"QtCore4.lib")#pragma comment(lib,"QtGui4.lib")#endifint main(int argc, char *argv[]){ QApplication a(argc, argv); QPainter qPaint; QPixmap *qPixmap = new QPixmap(700,500); qPixmap->fill(Qt::green); qPaint.begin(qPixmap); qPaint.setRenderHint(QPainter::Antialiasing, true); QPen pen(QColor(255,0,0),1); qPaint.setPen(pen); QString string = "我是中国人"; QTextCodec* gbk_codec = QTextCodec::codecForName("system"); QString gbk_string = gbk_codec->toUnicode(string.toLatin1()); QFont font; font.setFamily("宋体"); font.setPixelSize(100); QFontMetricsF fontMetrics(font); QRectF rect = fontMetrics.boundingRect(QString("我是中国人")); qPaint.setFont(font); qPaint.drawText(0,200,gbk_string); qPaint.drawRect(0,100,500,100); //依次绘制单个字体,以确认SetPointSize和SetPixelSize() gbk_string = gbk_codec->toUnicode("我"); qPaint.drawText(0,400,gbk_string); gbk_string = gbk_codec->toUnicode("是"); qPaint.drawText(100,400,gbk_string); gbk_string = gbk_codec->toUnicode("中"); qPaint.drawText(200,400,gbk_string); gbk_string = gbk_codec->toUnicode("国"); qPaint.drawText(300,400,gbk_string); gbk_string = gbk_codec->toUnicode("人"); qPaint.drawText(400,400,gbk_string); qPaint.drawRect(0,300,500,100); qPaint.end(); qPixmap->save("C:/a.jpg","JPEG"); qPixmap->save("C:/a.png","PNG"); qPixmap->save("C:/a.gif","GIF"); qPixmap->save("C:/a.bmp","BMP"); if(qPixmap) { delete qPixmap; qPixmap = NULL; } return a.exec(); return 0;}