做网站排行,前端网站开发流程图,如何查询网站的备案信息,中国建设银行官网站黄金部王毅一、要求
Qt Creator Ui中的Label标签控件显示一张Logo图片#xff0c;要求图片自适应控件的大小。
二、实现#xff08;代码#xff09;
QImage Image;//声明QImage 对象
Image.load(:/image/image/logo.jpg);//加载图片#xff0c;前提是该图片存在项目的…一、要求
Qt Creator Ui中的Label标签控件显示一张Logo图片要求图片自适应控件的大小。
二、实现代码
QImage Image;//声明QImage 对象
Image.load(:/image/image/logo.jpg);//加载图片前提是该图片存在项目的资源文件中
QPixmap pixmap QPixmap::fromImage(Image);//QPixmap引入Image
int with ui-label_logo-width();//设置宽度
int height ui-label_logo-height();//设置高度
QPixmap fitpixmap pixmap.scaled(with, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); // 饱满填充
//QPixmap fitpixmap pixmap.scaled(with, height, Qt::KeepAspectRatio, Qt::SmoothTransformation); // 按比例缩放
ui-label_logo-setPixmap(fitpixmap);//lable_logo 添加image
三、实现Qt Creator
另一种方式是在Qt Creator中直接设置选中该Label在属性栏目中找到QLabelpixmap中选择资源勾选scaledContents即可自适应。