qt 保存绘制在控件图片

在Qt中,如何保存绘制在控件label中的图片... 在Qt中,如何保存绘制在控件label中的图片 展开
 我来答
山水阿锐
2015-05-28 · TA获得超过34.3万个赞
知道顶级答主
回答量:23.7万
采纳率:91%
帮助的人:3.2亿
展开全部
其构造函数可以设置参考坐标轴,及其缩放动作,默认其他轴与参考轴的比例为1.0。setExpandingDirection函数可以指定在固定好参考轴后,另一轴拉伸时的模式,QwtPlotRescaler::ExpandBoth参数是指向两边扩展。
在找到这个类前,我有一个手动写法,原理是将QwtPlotZoomer的zoomed(const QRectF &)信号与在它所在的QwtPlot类中编写的槽相连,并重写QwtPlot类中的resizeEvent事件:

void TrackPlot::zoomedSlot(const QRectF &rectF)
{
QPointF centerPoint = rectF.center();

double Ratio = rectF.width() / rectF.height();
double hvRatio = double(canvas()->width()) / double(canvas()->height());

if(Ratio > 1)
{
double scaleFactor = hvRatio / Ratio > 1 ? hvRatio / Ratio : 1;

setAxisScale(xBottom, centerPoint.x() - scaleFactor * rectF.width() / 2.0,
centerPoint.x() + scaleFactor * rectF.width() / 2.0);
double step = axisStepSize(xBottom);
setAxisScale(yLeft, centerPoint.y() - scaleFactor * rectF.width() / (2.0 * hvRatio),
scaleFactor * centerPoint.y() + scaleFactor * rectF.width() / (2.0 * hvRatio), step);
}
else
{
double scaleFactor = Ratio / hvRatio > 1 ? Ratio / hvRatio : 1;

setAxisScale(yLeft, centerPoint.y() - scaleFactor * rectF.height() / 2.0,
centerPoint.y() + scaleFactor * rectF.height() / 2.0);
double step = axisStepSize(yLeft);
setAxisScale(xBottom, centerPoint.x() - scaleFactor * rectF.height() * hvRatio / 2.0,
centerPoint.x() + scaleFactor * rectF.height() * hvRatio / 2.0, step);
}

replot();
}

void TrackPlot::resizeEvent(QResizeEvent *ev)
{
QwtPlot::resizeEvent(ev);

if(ev->oldSize().width() > 5)
{
double hRatio = double(ev->size().width()) / double(ev->oldSize().width());
double vRatio = double(ev->size().height()) / double(ev->oldSize().height());

if(hRatio != 1)
printf("");

double xLowBound = axisScaleDiv(xBottom).lowerBound();
double xUpperBound = axisScaleDiv(xBottom).upperBound();
double yLowBound = axisScaleDiv(yLeft).lowerBound();
double yUpperBound = axisScaleDiv(yLeft).upperBound();

setAxisScale(xBottom, hRatio * xLowBound, hRatio * xUpperBound);
double ystep = axisStepSize(xBottom);
setAxisScale(yLeft, vRatio * yLowBound, vRatio * yUpperBound, ystep);

replot();
}
else
{
double minX = axisScaleDiv(xBottom).lowerBound();
double maxX = axisScaleDiv(xBottom).upperBound();
double minY = axisScaleDiv(yLeft).lowerBound();
double maxY = axisScaleDiv(yLeft).upperBound();

QRectF rectF = QRectF(minX, minY, maxX - minX, maxY - minY);

QPointF centerPoint = rectF.center();

double Ratio = rectF.width() / rectF.height();
double hvRatio = double(canvas()->width()) / double(canvas()->height());

if(Ratio > 1)
{
double scaleFactor = hvRatio / Ratio > 1 ? hvRatio / Ratio : 1;

setAxisScale(xBottom, centerPoint.x() - scaleFactor * rectF.width() / 2.0,
centerPoint.x() + scaleFactor * rectF.width() / 2.0);
double step = axisStepSize(xBottom);
setAxisScale(yLeft, centerPoint.y() - scaleFactor * rectF.width() / (2.0 * hvRatio),
scaleFactor * centerPoint.y() + scaleFactor * rectF.width() / (2.0 * hvRatio), step);
}
else
{
double scaleFactor = Ratio / hvRatio > 1 ? Ratio / hvRatio : 1;

setAxisScale(yLeft, centerPoint.y() - scaleFactor * rectF.height() / 2.0,
centerPoint.y() + scaleFactor * rectF.height() / 2.0);
double step = axisStepSize(yLeft);
setAxisScale(xBottom, centerPoint.x() - scaleFactor * rectF.height() * hvRatio / 2.0,
centerPoint.x() + scaleFactor * rectF.height() * hvRatio / 2.0, step);
}

replot();
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式