简体   繁体   English

设置从磁盘加载的背景图像

[英]Set background images loaded from disk

I would like change the QFrame Background at runtime, but, i would load the background from disk(an image). 我想在运行时更改QFrame背景,但是,我会从磁盘加载背景(图像)。 Setting stylesheet at QFrame not work's, because image isn't in resources. 在QFrame上设置样式表不起作用,因为图像不在资源中。

One way is set a QPushButton icon, for example: 一种方法是设置QPushButton图标,例如:

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

But, an QPushButton isn't useful to me. 但是,QPushButton对我没用。 I need to put other things inside of QFrame. 我需要把其他东西放在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)");

You could also try something like this: 你也可以尝试这样的事情:

QPalette pal;
pal.setBrush( ui.frame->backgroundRole(), QBrush( QImage( "/images/01.png" ) ) );
ui.frame->setPalette( pal );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM