adding an object to a Designer-made UI
-
I'd like to return to this subject, at a bit higher level. Let's say I'm writing a new app that can build and run on a variety of platforms, with widely varying screen resolutions.
Is it possible/advisable to write an app that doesn't specify any absolute sizes at all? In other words, can/should I allow Qt to make all of these decisions for me? And if so, what do I use to convey general guidelines to Qt, such as how much of the screen to consume, aspect ratio of the main window, etc?
I know these are vague questions...this is because I don't know what I don't know.
Thanks...
-
I'd like to return to this subject, at a bit higher level. Let's say I'm writing a new app that can build and run on a variety of platforms, with widely varying screen resolutions.
Is it possible/advisable to write an app that doesn't specify any absolute sizes at all? In other words, can/should I allow Qt to make all of these decisions for me? And if so, what do I use to convey general guidelines to Qt, such as how much of the screen to consume, aspect ratio of the main window, etc?
I know these are vague questions...this is because I don't know what I don't know.
Thanks...
@mzimmers
Hi
If you design your application with layouts
http://doc.qt.io/qt-5/examples-layouts.html
you are able to specify how you want the app to use the available space
for a given device. You can then use bitmap of multiple resolutions or SVG
to allow crisp viewing without scaling artifacts.
Each widget can specify how it should be scaled. Like keep to minimum
or take all space. This is controlled by
http://doc.qt.io/qt-5/qsizepolicy.html -
@mzimmers
Hi
If you design your application with layouts
http://doc.qt.io/qt-5/examples-layouts.html
you are able to specify how you want the app to use the available space
for a given device. You can then use bitmap of multiple resolutions or SVG
to allow crisp viewing without scaling artifacts.
Each widget can specify how it should be scaled. Like keep to minimum
or take all space. This is controlled by
http://doc.qt.io/qt-5/qsizepolicy.html@mrjj thanks for that link...I now understand size policy and size hints a lot better (though I'm going to have to experiment a little to fully grasp them).
I did read something that confused me, in the explanation of SizePolicy::Expanding, it says:
The sizeHint() is a sensible size, but the widget can be shrunk and still be useful. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a horizontal slider).
Shouldn't "shrunk" be "expanded" here?
-
@mrjj thanks for that link...I now understand size policy and size hints a lot better (though I'm going to have to experiment a little to fully grasp them).
I did read something that confused me, in the explanation of SizePolicy::Expanding, it says:
The sizeHint() is a sensible size, but the widget can be shrunk and still be useful. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a horizontal slider).
Shouldn't "shrunk" be "expanded" here?
@mzimmers said in adding an object to a Designer-made UI:
Shouldn't "shrunk" be "expanded" here?
Nope, they mean that
sizeHint()
doesn't impose any restriction on the minimal size of the widget (contrary toQSizePolicy::Minimum
). It's just a way to suggest what an appropriate size would be, from there on the widget will try to grab as much as it can, but it can be also shrunken if that's needed for the layout management. -
@mzimmers said in adding an object to a Designer-made UI:
Shouldn't "shrunk" be "expanded" here?
Nope, they mean that
sizeHint()
doesn't impose any restriction on the minimal size of the widget (contrary toQSizePolicy::Minimum
). It's just a way to suggest what an appropriate size would be, from there on the widget will try to grab as much as it can, but it can be also shrunken if that's needed for the layout management.@kshegunov oh, I see (I think) -- it means it can grow or shrink, and it should grow if it can, right?
So, if you had a widget that you wanted at least a certain size X, but you wanted it at X*2, or even more if necessary, you'd use this setting, right? And set the minimum size to X?
-
@kshegunov oh, I see (I think) -- it means it can grow or shrink, and it should grow if it can, right?
So, if you had a widget that you wanted at least a certain size X, but you wanted it at X*2, or even more if necessary, you'd use this setting, right? And set the minimum size to X?
Yes on both counts.
-
Hey, this is pretty cool stuff once you get used to it. I was expecting a lot more hassle based upon reading through the documentation, but once you start, it's not bad at all.
I have a few random issues currently:
-
my main widget has a vertical layout with 4 areas in it. Can I control the order (top to bottom) of these areas through object properties, or do I have to drag and drop?
-
What is the setting on a QLabel to ensure that all the text is visible?
-
I'm using another QLabel to display a SVG pixmap of our logo. How do I preserve aspect ratio during scaling?
Thanks...
-
-
Hey, this is pretty cool stuff once you get used to it. I was expecting a lot more hassle based upon reading through the documentation, but once you start, it's not bad at all.
I have a few random issues currently:
-
my main widget has a vertical layout with 4 areas in it. Can I control the order (top to bottom) of these areas through object properties, or do I have to drag and drop?
-
What is the setting on a QLabel to ensure that all the text is visible?
-
I'm using another QLabel to display a SVG pixmap of our logo. How do I preserve aspect ratio during scaling?
Thanks...
Hi
Yeah layouts are first pretty annoying and later it seems kinda natural.-
The insertion order will give the order. Not sure you can swap them runtime with code.
Normally you drag and drop to rearrange. -
you can enable word wrap. It will not scale the font used. That must be hand programmed if desired.
-
Make small custom class based on QLabel that uses
http://doc.qt.io/qt-5/qpixmap.html#scaled
and Qt::KeepAspectRatio
You can google it. Not an uncommon question.
https://stackoverflow.com/questions/8211982/qt-resizing-a-qlabel-containing-a-qpixmap-while-keeping-its-aspect-ratio
-
-
Hi
Yeah layouts are first pretty annoying and later it seems kinda natural.-
The insertion order will give the order. Not sure you can swap them runtime with code.
Normally you drag and drop to rearrange. -
you can enable word wrap. It will not scale the font used. That must be hand programmed if desired.
-
Make small custom class based on QLabel that uses
http://doc.qt.io/qt-5/qpixmap.html#scaled
and Qt::KeepAspectRatio
You can google it. Not an uncommon question.
https://stackoverflow.com/questions/8211982/qt-resizing-a-qlabel-containing-a-qpixmap-while-keeping-its-aspect-ratio
@mrjj thanks for the answers. I'm a little surprised by your answer to #2...if this is true, maybe I'm not using the best object. The goal was to have two QLabels (side by side) at the top of my main widget. On the left would be our logo, while on the right would be a title. I was hoping that the size of the title label would auto expand to show the entire text of the title. Is there a better way to do this?
Also, I think as an alternative to creating a a custom class for #3, I can just modify the object properties...yes?
-
-
@mrjj thanks for the answers. I'm a little surprised by your answer to #2...if this is true, maybe I'm not using the best object. The goal was to have two QLabels (side by side) at the top of my main widget. On the left would be our logo, while on the right would be a title. I was hoping that the size of the title label would auto expand to show the entire text of the title. Is there a better way to do this?
Also, I think as an alternative to creating a a custom class for #3, I can just modify the object properties...yes?
-
@mzimmers
Hi
If there is room for the text, it will work. If not enough room and no wordwrap, it will just cut the text.
Im not sure how it should fit the text if no room ?About 3:
What properties do you think of ?@mrjj I was hoping that some display widget could auto-size to reveal all of its text on a single line. This may be asking for too much.
Regarding the logo, I'm doing this right now:
ui->logoLabel->setPixmap(logo.scaled(logoSize, Qt::KeepAspectRatio, Qt::SmoothTransformation))
I'm still working with it (the image quality is currently poor) but I don't see the need for a custom class.
-
@mrjj I was hoping that some display widget could auto-size to reveal all of its text on a single line. This may be asking for too much.
Regarding the logo, I'm doing this right now:
ui->logoLabel->setPixmap(logo.scaled(logoSize, Qt::KeepAspectRatio, Qt::SmoothTransformation))
I'm still working with it (the image quality is currently poor) but I don't see the need for a custom class.