QT background image not showing using stylesheets - c++

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.

Related

QT Dialog box when building is cutting off my UI content, how do I resize the dialog box so this does not happen?

Here is the example of what is happening. Above is the simple design of my UI, but below when I build my project, everything within is getting cut. What is the issue? I can't seem to find it despite trying to resize a bunch of my widgets.
This is what my QT dialog box structure looks like right now.
Then in my main.cpp file I just had
w.setFixedSize(560,180);
w.setWindowTitle("Servo Control");
Update: I applied a grid layout to the outermost hierarchy and this fixed my problem. Strange though because the video I was following did not have any layout on it, but did not run into the same problem.

Set a scale for a background-image

I just created a resource file for my project, which got 5 prefixes (Window, background, etc).
My main problem is that, when using the Qt Designer, I go to stylesheet, open it up, Add resource -> background-image.
Unfortunately my picture is way too big for my window, and I can't seem to put it to scale using designer.
After reading some topics on the forums, I have tried to put this in the "stylesheet edit" :
background-image: url(:/background/Backgrounds/Fondecran1.jpg) 0 0 0 0 stretch stretch;
in place of
background-image: url(:/background/Backgrounds/Fondecran1.jpg);
Can anyone help me put it to scale ?
Is there a way it can "adapt" as well as it can to changes in the window size ?
Thank you all in advance for your answers.
Instead you may need to use border-image.
Look into the below content in the link provided.
A background-image does not scale with the size of the widget. To provide a "skin" or background that scales along with the widget size, one must use border-image. Since the border-image property provides an alternate background, it is not required to specify a background-image when border-image is specified. In the case, when both of them are specified, the border-image draws over the background-image.
http://doc.qt.io/qt-5/stylesheet-customizing.html

Can't use a transparent BMP with MFC Button control

I am really confused here ...
I am trying to add a MFC Button control onto my dialog in the IDE.
I want it to just show a BMP file. I have another already on the dialog that shows with a transparent background.
This is the image for the good button:
This is the other button image I downloaded. But it is PNG:
I have tried to convert it so that it is 32 bit BMP so that it is transparent:
But it is failing. It shows with a black background:
You can see on that screenshot that the lower image shows OK. But not the new one. How do I fix this image file?
Update:
I used a different image in the end for the question mark. But for others I ended up using PNG and manually using the load method as outlined below:

QtWidget background image issue (Qt Creator)

I want to add a background image to a Qt Widget. I am using Qt Creator 4.0.2 on Linux 64-bit.
The issue is when I am choosing a background image, it doesn't show (although a part of image can be seen around the PushButtons I have on page) when I run the program. However when choosing a background color works perfect.
(Using CSS)
Here are the screens :
With background-image
With background-color
Try and set it through the style sheet:
yourWidget->setStyleSheet("background-image: url(<path-to-image>/image.png)")
It works for me.

Making Qt Widgets Stretch and Scale w/ Main Window

I'm wondering if there is a way to make Qt widgets within a QMainWindow widget stretch and scale as the size of the main window is stretched and shrunk. Basically, I'd like the entire window and it's contents to have the same appearance except for size:
At the only way I can think to accomplish this is to get the size of the main window, do the math for every single widget, and reset their sizes any time the main window size is changed, but I'm thinking there's an easier way.
I like this video tutorial on youtube. I'll help you create a layout using QLayout classes. If you use QtCreator/Designer, you can also take a look at the auto-generated ui_MainWindow.XXX file that will clue you in on how it uses some of the UI classes.
As always, QtCreator/Designer has a bunch of hints and tips so you should be able to dig up from the documentation that's embedded in the application.