Qt给控件添加图片

双击qrc文件,选择下面的addFiles,将图片添加进来,然后选中图片右键Select All

设置控件字符:

ui.btnSet->setText("");

设置资源:

cpp 复制代码
ui.btnSet->setStyleSheet("QPushButton{background-image:url(:/QtWidgetsApplication2/resources/set.png)}");

设置无边框:

cpp 复制代码
ui.btnSet->setStyleSheet("QPushButton{background-image:url(:/QtWidgetsApplication2/resources/set.png);border:none}");

点击变色:

cpp 复制代码
ui.btnSet->setStyleSheet("QPushButton{background-image:url(:/QtWidgetsApplication2/resources/set.png);border:none}\
		QPushButton::hover{background-color:rgb(200,200,200)}");

给Label添加图片:

cpp 复制代码
ui.label_logo->clear();
	QPixmap* pix = new QPixmap(":/QtWidgetsApplication2/resources/logo.jpg");
	//自适应尺寸
	pix->scaled(ui.label_logo->size(),Qt::KeepAspectRatio);
	ui.label_logo->setScaledContents(true);
	ui.label_logo->setPixmap(*pix);
相关推荐
Momo__1 小时前
VueUse createReusableTemplate —— 单文件组件内的模板复用神器
前端·vue.js
程序员小富1 小时前
我开源了一个开发者专属的智能 JSON 工具,得到了媳妇高度认可
前端·vue.js·后端
JustHappy2 小时前
「软件设计思想杂谈🤔」“切图仔”也能懂编译原理?框架源码也许没那么难。聊聊 Vue 的编译(上)
前端·javascript·vue.js
xcyxiner1 天前
DicomViewer (dcmtk读取dcm文件)5
qt
假如让我当三天老蒯1 天前
Options API(选项式 API) 和 Composition API(组合式 API)
前端·vue.js·面试
xcyxiner2 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner2 天前
DicomViewer (添加模型类)3
qt
xcyxiner3 天前
DicomViewer (目录调整) 2
qt
xcyxiner3 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
秃头网友小李4 天前
前端难点:keep-alive 缓存什么?RouterView 的 key 为什么要带 scopeId?
前端·vue.js