PDA

View Full Version : Creating a custom layout for QWidget



prajain
13th May 2015, 12:04
How can I place widgets relatively to each other in a QWidget without using any layout widget (like QGridLayout, QLayout etc) in Qt?
Can i use grabWidget() and paint widgets to QWidget, using information from the QRect() of other widgets? If yes, how?

wysota
13th May 2015, 15:20
Why you don't want to use layouts?

d_stranz
13th May 2015, 17:16
Can i use grabWidget() and paint widgets to QWidget, using information from the QRect() of other widgets? If yes, how?

Yes, of course you can do that, and you'll get a QWidget with pictures of other widgets in it. They aren't QWidgets, so your users won't be able to interact with them. Why on earth would you want to do something like that?

I suspect that you are not correctly designing your layouts, which is why you are trying to reinvent the wheel.

prajain
14th May 2015, 05:58
The reason is historical. Just tell me if you can do that. I want users to interact with the widgets.

Added after 5 minutes:

Because I don't want to put my widgets in a grid-type manner. Can i do that?

Because I don't want to put my widgets in a grid-type manner or horizontal or vertical manner. Can i do that?

wysota
14th May 2015, 07:24
The reason is historical. Just tell me if you can do that. I want users to interact with the widgets.
You can postion all your widgets manually if you want. But that's usually a bad idea.


Because I don't want to put my widgets in a grid-type manner. Can i do that?

Because I don't want to put my widgets in a grid-type manner or horizontal or vertical manner. Can i do that?

What manner do you want to put your widgets in then?

prajain
15th May 2015, 05:24
I wanted to put the widgets relative to other widgets. For example, I can place the widget either right or left and either top or bottom of a widget. Something like that.

wysota
15th May 2015, 05:58
You can do that with existing layouts or you can implement a custom layout to do this.

d_stranz
15th May 2015, 16:47
I wanted to put the widgets relative to other widgets. For example, I can place the widget either right or left and either top or bottom of a widget. Something like that.

It sounds like you want something like "glue", which is used in another layout system the details of which I don't remember. "Interviews", maybe?

You can do this with grid, horizontal, vertical or a combination of layouts in a hierarchy. If you want to do this dynamically at runtime, then you need a way to specify the locations of widgets relative to each other, and build up the layouts to reflect that relationship. So if you have two widgets that are located top and bottom relative to each other, you create a a vertical layout, insert the top widget then the bottom widget.

If you don't want the widgets to expand their sizes or spacings as the container widget resizes, then insert horizontal or vertical spacers into the layouts.