Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to adjust size of two widgets which are under a layout and please tell me the procedure to report to Qt admins about a bug or limitation of Qt
First of all I would like to say sorry for my poor english in following section.
I am trying to design an ui in Qt. This ui should have a special feature that it should resize according to dpi. Somehow i managed to calculate the required size of base widget for specific dpi.But whenever i resize base widget. then size of base widget only increased/decreased. but size of child widgets remain same. For that, I searched a lot. Then I found that i have to use layouts. But the problem is that-
If I applied layout on (say two widgets )widgets, then i can't control size of widgets . I can control size of widget till an extend only such as by changing size policy etc.--
Here i am adding two pictures
This image after applying layouts.
This image before applying layouts or say this is required size of widgets after applying layout.
Note:- I am applying layout for resizing all widgets whenever i resize base widget. That is the only reason to use layout.
- How can i resize widgets as per i wish after applying layouts.?
- Is it possible to get full control for resizing widgets after applying layouts?
- If my second queries answer is no. Then can i say this is limitation of Qt?
- How can i report about it to Qt admins?? So that if there is any solution or any alternate they can explain about this matter.
Guys, Your suggestions are much valuable for me.
Thank u in advance.
At this link, I have posted all the information.
Please provide me some suggestion.
[EDIT: I have merged your threads. This is the correct place. --JKSH]
I have posted here because I think it may be also correct place. Please give some attention to this thread. So that problem of resizing a widget after using a layout can be solved.
This is not a limitation nor a bug. That is how layouts are designed and it's a good design trialed and tested in practice by many.
If you set a layout then you don't control sizes. You can control proportions, hint on preferred size and use policies. You can add margins, padding and stretches to control empty space, but the layout sets the actual size.
To make it more clear - layouts are like hiring a chauffeur for your car. They are for your convenience so that you don't have to do all the little things involved with driving yourself. You can suggest a route, you can tell him when to stop or go faster, but he is the one that turns the wheel and pushes the pedals.
It's not a bug that you can't steer when you're not the one driving. It wouldn't be a good thing to let you both drive at the same time either ;)
You can gain a significant control over what your form looks like using layouts and they will spare you from calculating pixels yourself. You can make constant sizes, proportional resizing, relational resizing on siblings etc.
Tell us what you want to achieve and maybe we can help you set the layout appropriately. The usual problem is that layout is set only on "some" parts of the form like in your picture. With layouts it's usually best to do all or none, otherwise it just gets complicated.
Thanks JKSH for putting my this thread at correct place.
Thank u so much Chris for your valuable suggestion. I understand valuation of layouts. As you took example of chauffeur . It helped me to understand it very clear.
My basic problem is -
- If I increase or decrease size of base widget, then size of all its child widget should be increased or decreased proportionally.
For the above reason only, I am using layouts. and I have to resize base widget according to dpi.
Is there any alternate so that i can get such base widget and all its child widget which can resize according to dpi?
Qt widgets are DPI-aware by default. You don't have to do anything to make it work. Just place everything in layouts. Everything - meaning there is no red circle icon in your object tree in the designer.
Here's how DPI scaling works (no special code whatsoever):
Yes. I am agree with you Chris. Qt widgets are DPI-aware by default, but I have to place everything into the layouts.
so, i have no full control over resizing of widgets after applying layout. and as i want size of widgets that is very difficult. because i have to put all the widgets according to an image which is set in the background.
So i must say that i have started from where. i reached at there again.
Note - when i am changing dpi then widgets size are changed according to dpi but size of image(which is set on background) remain same and multiple images are added. This is another problem which i am facing.
If you need this fine-grained, pixel-perfect control then layouts are clearly not for you. Just implement resizeEvent() and place everything where you want it.
For the background image you will either have to provide multiple versions of the background and select the right one depending on the current DPI or draw and stretch the image however you want. You can do that for example by reimplementing paintEvent() of the window.
Thanx Chris. Now I'll try with resize event().