当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - QT background image not showing using stylesheets

问题描述:

I'm using QT for C++ and I set this stylesheet code:

QFrame {

background-image: url(img.png);

}

The image doesn't show! It's located in the debug directory inside the QT directory. Why doesn't it show?

edit:

doesn't even work with the resource system

edit 2:

It shows now, but only if I use QWidget instead of QFrame. The only problem is that the image repeats when I resize the window. How do I make it stretch normally instead?

edit 3:

OK, I used JUST border-image now and it stretches. However, it's glitchy(if you move a bit fast you can go over the original image), and very slow(if you're not resizing slowly enough, it will stutter and until it manages to stretch there will be a white gap). Can't I get it to resize normally? =/

Using this stylesheet code:

QWidget {

border-image: url(:/images/img.png);

}

edit 4:

Well if I'm already at it.. what about clickable areas in images? Is that possible?

edit 5:

come on..anyone? this is important

网友答案:

Add your image to resources (.qrc file) of your application. Then refer to it in your stylesheet:

QFrame
{
 background-image: url(:/Style/img.png);
}
网友答案:

I think you should use Qt Resource System instead of having an image inside the folder. Images can also be speicified without the url function.

分享给朋友:
您可能感兴趣的文章:
随机阅读: