双击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);