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

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

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

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

图片描述

阅读 4.4k
3 个回答

你应该对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.

缩放图片后再进行绘制

你这里的QPainter painter(this)中的this是你wuziqi这个窗口吗?

你的那个qipan的控件就没有铺满窗口……

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题