从磁盘加载设置背景图片 [英] Set background images loaded from disk

查看:138
本文介绍了从磁盘加载设置背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变QFrame背景在运行时,但是,我会从磁盘加载背景(图像)。
在QFrame设置样式表行不通的,因为图像是不是在资源

I would like change the QFrame Background at runtime, but, i would load the background from disk(an image). Setting stylesheet at QFrame not work's, because image isn't in resources.

一种方法是设置一个QPushButton图标,例如:

One way is set a QPushButton icon, for example:

QPixmap img("/images/01.png");
ui.pushButton->setIcon(QIcon(img));

但是,一个QPushButton对我来说并不实用。我需要把QFrame里面其他的东西。

But, an QPushButton isn't useful to me. I need to put other things inside of QFrame.

推荐答案

这是我在你的问题的理解,你不希望使用的资源?
如果是这样的话,你可以这样做:

From what I understood in your question, you do not want to use Resources ? If that is the case, you could do something like:

ui->frame->setFrameStyle(QFrame::StyledPanel);
ui->frame->setStyleSheet("background-image: url(C:/test.jpg)");

这篇关于从磁盘加载设置背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆