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
Related
i have made a figure in inkscape and realized that is a landscape orientation with width 608 and height 495. The problem is that i want to make it ready for publication and ideally i want it in portrait orientation and much smaller. I see here in Document Properties that the size for A4 is 210x297. Can somebody tell me how i can accomplish this task?
thanks in advance
You are on the right path. Go to Menu.
File > Document Properties
And you can change the size of your design by setting the custom value in the Custom Size option in Document Properties Window. If you wish you can also change the unit in which you want to work. For your reference, I am attaching a screenshot.
I have a Qt app that runs on macOS. I found a way to change the color of the titlebar here, however I want to take it a step further. I want to mimic the titlebar that the Slack and Discord apps use. For example:
As you can see, the color of the controls in the window extend to the very top of the app's window. I figure there are two ways to accomplish what I want:
I can build on the code pasted above. Looking through some of the Apple developer documentation, I think I can create a couple NsWindows on top of the titlebar with whatever width I want and attach the titlebar as a parent for those windows. Once I do that I should be able to make the same backgroundColor() color call for each one. Of course, this will require me to keep track of when the controls or window are resized and adjust the NsWindows of the titlebar, and I am not sure what (if any) issues that could cause.
Maybe there is a way to essentially set the height of the titlebar to 0? I wonder if that's what the Discord app is doing because:
if you look closely, the edit box that says "Find or start a conversation" is vertically lined with the close, minimize and maximize buttons, as is the "Activity" label. But if the controls do extend to the top of the app's window then how are the standard app buttons getting painted?
I'd be curious to know how Slack and Discord accomplish this even though I know they're not using Qt.
I realize there is not a Qt solution since Qt does not paint the titlebar. I know this will be OS-specific, but since I do not have any real experience with Objective-C++ or working with Cocoa (all of my programming experience on macOS has been standard C++ with non-UI or Qt-based code) I'd appreciate any suggestions or guidance!
Natively this is done with fullSizeContentView and titlebarAppearsTransparent properties of NSWindow. Once you set them to true, you can draw or place controls beneath the title bar.
I'm making my own UI from scratch using OpenGL that is why I'm asking this and please don't make any discouragement as this is just a hobby project.
Currently, I'm stuck implementing how this scrollbars really work. In my current implementation, the content scrolls at the wrong step value as well as the thumb, meaning, I set the value manually like 1px step for each of them.
The structure of my scrollbar implementation is describe as follows:
I draw scrollbars i.e the main rectangle where the 3 button lies.
Those 3 buttons are, thumb, buttonBack and buttonNext.
All of them do the basic logic of scrollbars i.e when I click each one of them, they moved. But the whole part(scrollbar) don't know how to scroll contents
So what I did is: I make another object and I call it scrollarea
It has two scrollbars, vertical and horizontal scrollbar.
I made a function called scrollToX and scrollToY which
does what I named to them.
But the step values I set to them are
manually set up.
I try to google some scrollbar, scrollarea, scrollview or whatever you call to that scrollable rectangle thing, but all I see are implementation and I cannot find any guides how to build your own. I have no choice but to look at their implementation. I try my best to comprehend what they did but their implementation of how their whole UI structure is very different to mine, and I cannot find anything useful there.
So I ask again here if anybody can explain me well how to make a properly functional scrollbar.
Most specific things I'm really concerned of are:
How do I determine the thumb step value?
How do I determine the content step value?
All of these depend on your content -
Is it just an image ? If so, you only need to change the offset depending on the size of the image.
Is it a list of values like in Windows explorer ? Then you need to create a data structure first that contains all of it, and shows the content that fits within the window as it scrolls.
OpenGL does not fit into this discussion.
I'm developing a Qt application and it's currently in an internal beta test. One member of the company has Windows configured to display text larger than its normal size, which breaks my UI. The About page, for example, currently looks like this:
but under his settings, looks like this (note the clipped text):
Coming from a C#/Winforms background, I'm amazed that I can't seem to find some easily configurable label property such as Form.AutoSize that will automatically size the labels to fit their containing text. I've tried messing with sizePolicy, scaledContents, and a few other properties, but none seem to do this.
I've come across various threads (such as this one) which give instructions for scaling the text to the label, but I want to do the opposite - scale the label to the text to facilitate for those with enlarged text settings like my co-worker. Is there a straightforward way to do this?
There are at least three solutions to this problem.
Use layouts. Their contents are scaled according to the size of the window.
Make a code which is executed whenever window size is changed. In that code, you get the width of the longest text in the window (How?)(another way) and then set window wider than that.
Do the same as in solution #2, but execute the code only when the dialog is shown. After that, alter the window properties so that its size cannot be changed.
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.