How set QGridLayout's fixed size?
-
wrote on 30 Oct 2018, 14:06 last edited by
I created gridLayout, but it fits by default to the size of parent QDialog(which is very big), can't find proper function to set size of layout.
->setGeometry not working, and it's unusual because it accept only QRect as a param(strange).
->setVerticalSpacing also do nothing, i play with numbers, nothing changed.
I tried few more, but can't remember them now, here is those which at least do some effect:->setSizeConstraint() - with fixed or minimum options it changes my layout from default(dumb) size, to normal, so normal spacing between rows and all. BUT. It change whole parent QDialog :DDD
->setMargins do stuff, but there is no customisation, i did'nt found any ->setLeftMargin, or for other side, but such functions would do the thing.
-
wrote on 30 Oct 2018, 14:15 last edited by
Hi Engelard,
Did you try to use QSpacerItem?
Also, maybe you could provide us with some code to better understand what you try to achieve as well as where and why it doesn't work. -
Hi Engelard,
Did you try to use QSpacerItem?
Also, maybe you could provide us with some code to better understand what you try to achieve as well as where and why it doesn't work.wrote on 30 Oct 2018, 15:07 last edited by@ValentinMichelet No. I just want simple set size function for Label, so i would tell where is exactly borders of that label should be. No code will help you because my question is in lowest level of simplicity. But if you rly need:
topLayout = new QGridLayout(resultsDialog);
Size of resultsDialog 350200, size of topLayout is same, and i wish resize it to 50150, but not with help of setMargins, i need it be at left top corner of a widget.
-
wrote on 30 Oct 2018, 15:23 last edited by ValentinMichelet
OK, I'm not sure to fully understand your needs nor to fully know how Qt layouts work behind the scene but here are some things I would try that may be helpful (at least I hope so) but that you maybe already tried yourself:
- Try to create a UI file to better understand how parameters work
- Play with layoutLeftMargin (yes, you can modify left, top and so on margins of your layout from the Designer)
- Play with constraints policies of your widgets
- Play with your label's alignment
- Play with layoutSizeConstraint
- Play with Spacers (horizontal and vertical)
- Use style sheets to actually see the border of the label (this is only a debug purpose but may help better understand what is really happening)
- Investigate how sizeHint mechanism works, for it may be resizing automatically things behind your back
Also, instead of some code snippets, maybe you could provide us with some sort of mockup of what you try to achieve, so that I can try to replicate it with some code?
-
wrote on 30 Oct 2018, 15:38 last edited by
I have to say that i really surprised, such simple and "first" thing that should be - is settingSize of object/widget/container, it must be an easyiest thing.
-
OK, I'm not sure to fully understand your needs nor to fully know how Qt layouts work behind the scene but here are some things I would try that may be helpful (at least I hope so) but that you maybe already tried yourself:
- Try to create a UI file to better understand how parameters work
- Play with layoutLeftMargin (yes, you can modify left, top and so on margins of your layout from the Designer)
- Play with constraints policies of your widgets
- Play with your label's alignment
- Play with layoutSizeConstraint
- Play with Spacers (horizontal and vertical)
- Use style sheets to actually see the border of the label (this is only a debug purpose but may help better understand what is really happening)
- Investigate how sizeHint mechanism works, for it may be resizing automatically things behind your back
Also, instead of some code snippets, maybe you could provide us with some sort of mockup of what you try to achieve, so that I can try to replicate it with some code?
wrote on 30 Oct 2018, 15:42 last edited by Engelard@ValentinMichelet said in How set QGridLayout's fixed size?:
Play with layoutLeftMargin (yes, you can modify left, top and so on margins of your layout from the Designer)
There is no such function, i told it when created this topic. And there is no possibility to use Designer since parent widget and layouts in it are created programmatically.
For illustation, here is what i've got from simple code, as you can see, layout which contain 4 labels fit whole window:
And size of my QGridLayout should be like that(red rect):
-
wrote on 30 Oct 2018, 15:47 last edited by
Again, I'm not sure to fully understand your problem (hence the mockup) so there may be simpler solutions.
AFAIK, with only a dialog that has a grid layout and a label inside, your label will always be centered and the layout of the QDialog will occupy the entire size (hence the fact that your dialog and its layout are both 350x200). Now you can add spacers (horizontal and vertical) to push your label on the top left corner, right? Or do you really need to have a layout that is smaller than your QDialog? Also, are there other widgets inside your QDialog? -
Again, I'm not sure to fully understand your problem (hence the mockup) so there may be simpler solutions.
AFAIK, with only a dialog that has a grid layout and a label inside, your label will always be centered and the layout of the QDialog will occupy the entire size (hence the fact that your dialog and its layout are both 350x200). Now you can add spacers (horizontal and vertical) to push your label on the top left corner, right? Or do you really need to have a layout that is smaller than your QDialog? Also, are there other widgets inside your QDialog?wrote on 30 Oct 2018, 15:48 last edited by@ValentinMichelet said in How set QGridLayout's fixed size?:
Again, I'm not sure to fully understand your problem
just added an illustrations with pictures
-
wrote on 30 Oct 2018, 15:55 last edited by ValentinMichelet
@Engelard said in How set QGridLayout's fixed size?:
just added an illustrations with pictures
Yep, bad timing =) Thanks for the pictures!
There is no such function, i told it when created this topic.
I know, but what I did not know was you could not use the designer.
From your mockup, I'd go for QSpacerItem as well as setSizePolicy/setMinimumSize/setMaximumSize methods for the label.
Your QDialog layout's size will always fit your QDialog's size AFAIK. But maybe I'm wrong, so I'll let other people answer this if they know more about it. -
wrote on 30 Oct 2018, 16:08 last edited by Engelard
@ValentinMichelet said in How set QGridLayout's fixed size?:
I'd go for QSpacerItem as well as setSizePolicy/setMinimumSize/setMaximumSize methods for the label.
No! I'm still believing in Qt! That's impossible that there is no functionality for resizing. Btw, just tried that stuff, totally no effect:
P.S. label setMinimumSize/setMaximumSize change nothing(
-
wrote on 30 Oct 2018, 16:33 last edited by Engelard
I don't know, should i report a bug or something, nothing working, setsizePolicies, setMinimumHeight of labels or layout, none of that function working, i tried like 20 functions already, what sense from all that stuff if it do no effect...
P.S. Here is the code, anybody can just insert it in your dummy project to try:
resultsDialog = new QDialog(this, Qt::MaximizeUsingFullscreenGeometryHint | Qt::WindowSystemMenuHint); resultsDialog->setMinimumSize(300, 450); resultsDialog->setWindowFlag(Qt::WindowCloseButtonHint, true); resultsDialog->setModal(true); resultsDialog->setWindowTitle("final output"); resultsDialog->show(); topRegLB = new QLabel("Most often results from '0' scans:", resultsDialog); firstRegLB = new QLabel("#1: ----", resultsDialog); secondRegLB = new QLabel("#2: -----", resultsDialog); thirdRegLB = new QLabel("#3: ------", resultsDialog); topLayout = new QGridLayout(resultsDialog); topLayout->addWidget(topRegLB, 0, 0, 1, 2); topLayout->addWidget(firstRegLB, 1, 0); topLayout->addWidget(secondRegLB, 2, 0); topLayout->addWidget(thirdRegLB, 3, 0);
-
wrote on 30 Oct 2018, 17:34 last edited by Engelard
-
wrote on 30 Oct 2018, 18:36 last edited by ValentinMichelet
Oh yeah, the rowStretch is important too, I forgot. But again, the size of the QDialog’s layout is the size of the QDialog itself. I don’t see how to change that. If anyone knows, I’m more than interested.
Would it be possible to use a child layout? -
Oh yeah, the rowStretch is important too, I forgot. But again, the size of the QDialog’s layout is the size of the QDialog itself. I don’t see how to change that. If anyone knows, I’m more than interested.
Would it be possible to use a child layout?wrote on 30 Oct 2018, 19:52 last edited by@ValentinMichelet said in How set QGridLayout's fixed size?:
the size of the QDialog’s layout is the size of the QDialog itself.
This is probably the most important combination of words in whole topic, clarify alot.
-
@ValentinMichelet said in How set QGridLayout's fixed size?:
the size of the QDialog’s layout is the size of the QDialog itself.
This is probably the most important combination of words in whole topic, clarify alot.
wrote on 31 Oct 2018, 04:22 last edited by@Engelard said in How set QGridLayout's fixed size?:
@ValentinMichelet said in How set QGridLayout's fixed size?:
the size of the QDialog’s layout is the size of the QDialog itself.
This is probably the most important combination of words in whole topic, clarify alot.
Along with
the layout of the QDialog will occupy the entire size (hence the fact that your dialog and its layout are both 350x200).
and
Your QDialog layout's size will always fit your QDialog's size AFAIK.
Which are essentially three different ways to express the same idea ;)
1/15