label_10->setStyleSheet(QString("QLabel { background-image: url(%1);background-color: rgb(231, 231, 231);border-radius: ...-Go服务器开发" />

ZBLOG

QString currentPath = QCoreApplication::applicationDirPath(); QString imagePath =currentPath + "/img/class.png"; ui->label_10->setStyleSheet(QString("QLabel { background-image: url(%1);background-color: rgb(231, 231, 231);border-radius: ...

在使用 QLabel 的样式表来设置背景图片时,可以通过指定 background-repeat 属性来控制背景图像的重复方式。如果你希望图片不重复填充,可以将其设置为 no-repeat。以下是修改后的代码示例:

QString currentPath = QCoreApplication::applicationDirPath();
QString imagePath = currentPath + "/img/class.png";
ui->label_10->setStyleSheet(QString(
    "QLabel { "
    "background-image: url(%1); "
    "background-color: rgb(231, 231, 231); "
    "border-radius: 5px; "
    "background-repeat: no-repeat; " // 添加此行
    "}"
).arg(imagePath));

// ui->label_10->setFixedSize(48, 48);
ui->label_10->setToolTip("班级");
ui->label_10->installEventFilter(this);

这样,背景图像将不会重复填充,如果需要调整位置,可以考虑添加 background-position 属性,例如:

"background-position: center;"

如果希望背景图像在标签中居中显示,可以添加这行代码,如下所示:

"background-image: url(%1); background-color: rgb(231, 231, 231); border-radius: 5px; background-repeat: no-repeat; background-position: center;"

这样就能确保图片不重复,并且可以根据需要调整显示位置。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:label_10->setStyleSheet(QString("QLabel { background-image: url(%1);background-color: rgb(231, 231, 231);border-radius: ...">https://golang.0voice.com/?id=21346

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?