tags:

views:

42

answers:

3

I'm trying to have a 2x2 QGridLayout arranged as follows:

+-----+-----+
|(1)  |(2)  |
+-----+     |
|(3)  |     |
+-----+-----+

I want to be able to expand (1) programatically to occupy the whole first row, like as follows:

+-----------+
|(1)        |
+-----+-----+
|(3)  |(2)  |
+-----+-----+

Actually, I want to expand and contract any widget to any direction.

I'm able to do this by just detecting what widget is in the cell I need to expand to. But the problem is that it is a pain to make this happen on any direction and any grid size, because I need to go back to the initial position of the just expanded widget (1), so I don't need to remember positions, except the one I'm expanding/contracting.

So, in the example above, I decided to just expand the widget to occupy the position 0,0 with column span of 2. This will result in overlapping widgets, which is ok for me. The problem is that widget (1) will be underneath (2), I guess because of order of insertion into the grid. Hence the question: how do I control a widget's overlap priority in a QGridLayout?

Thanks!

A: 

Perhaps you can make something like this work for you with some experimentation.

alt text

Both shots are of a QVBoxLayout with two QHBoxLayouts in them. You should be able to dynamically remove and add buttons from one QHBoxLayout to another. You can add or remove a spacer to determine if a button will span the whole width or not.

I realize that it is still adding and removing widgets but it might be a little easier than the grid layout.

Arnold Spence
A: 

I'm not sure that this will do what you want, but from what I understand you want to resize your three widgets in any way you want.

You could try to look into the QSplitter class. It allows you to change (manually or programmatically) the size of your widgets, a bit like the outlook separations.

It is really easy to use and may be flexible enough to give you what you want.

Hope this helps.

Live
A: 

I got the answer to my question. The solution is to call raise() on the widget I'm resizing. This "resizing" is actually a removeWidget from the layout and an addWidget to the layout (again), with the new cells and cell spans information. After this, I call raise() on the widget, and that's it.

Daniel