c++ - qt中使用图片不能铺满窗口

查看:271
本文介绍了c++ - qt中使用图片不能铺满窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

我尝试在窗口中添加图片并且铺满窗口,

但是在实际运行过程中显示成了这样

尝试改变目标矩形的大小也没有作用

解决方案

你应该对QPixmap做下缩放吧,该函数有方法scaledToWidth和scaledToHeight

QPixmap QPixmap::scaledToWidth(int width, Qt::TransformationMode mode = Qt::FastTransformation) const

Returns a scaled copy of the image. The returned image is scaled to the given width using the specified transformation mode. The height of the pixmap is automatically calculated so that the aspect ratio of the pixmap is preserved.

If width is 0 or negative, a null pixmap is returned.

缩放图片后再进行绘制

这篇关于c++ - qt中使用图片不能铺满窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆