PDA

View Full Version : QGraphicsLayout - same widths and heights for all cells, two items in the same cell



Palmik
16th February 2010, 16:44
Hi. I got a class sub-classing QGraphicsSvgItem and QGraphicsLayoutItem so it should be possible to add this item to QGraphicsLayout, right?
Now, I trying to figure how to create a grid layout where the cells are stretching (like in normal QGridLayout or QGraphicsGridLayout) but but all cells are squares. I would take the widest column or highest row and resize all rows and columns accordingly. Would that be somehow possible? If yes, how? I thought I would just subclass QGraphicsGridLayout and during each resize I would find the widest column or highest row and adjust width and height of the remaining columns and rows. However I did not find a way to get the actual width or height of the column or row respectively.
Another thing I would like to achieve with this layout is possibility to place more items into one cell - would that be somehow possible? If yes, how (briefly)? Or how would you imitate it. Again, I thought I would subclass QGraphicsItem create two QGraphicsGridLayouts as members (since I will only require 2 items at max on top of each other) do the resizing as I said in the first paragraph and than place the two layouts on top of each other (if possible) which should imitate the look of two overlapping items.
Thanks in advance.

Lykurg
16th February 2010, 16:52
Some hints:
use QGraphicsGridLayout::setColumnMaximumWidth() and QGraphicsGridLayout::setColumnMinimumWidth() with the same witdh and you have a fix width. Or for that better ust QGraphicsGridLayout::setColumnFixedWidth().
same with QGraphicsGridLayout::setRowMaximumHeight() ...


Two items in one cell is not possible but you can nest layouts.

Palmik
16th February 2010, 17:20
Well, I do not want the width to be fixed, I want it to stretch.
This is how normal QGraphicsGridLayout would look like
http://filebeam.com/83e65da71d4918bde6f53ea827dfc874.jpg
And this is how my layout would look like in this case - it would of course change if the view was resized.
http://filebeam.com/0afc8ec8acc6ff114cb7e579e605ba9c.jpg

I will look into nesting layouts and see if it could help me, thank you :)
Edit: I'm not sure if I got "nested layouts" right but does not that mean that I just put one layout into another's cell? If so, than thats is probably not what I could use here. :/

Lykurg
16th February 2010, 17:38
Well as I understand you you want a "fix" layout till a cell changes its size. If you get notice of a geometry change, reset the "fix" size or only set the minimum size to get grid with same cell boundings.

May be you provide a fast image mocup what you understand by "to place more items into one cell". Because if you put more items in one cell you have to lay them out => use a layout. And then you have a layout in a layout => nested layout.

Palmik
16th February 2010, 17:52
Yeah, I could do that with fix size... but, how do I get the widths of the columns or rows to determine which one is the widest?
Here is the image mockup
http://filebeam.com/45d50e19c602345995313fb66c666bcf.jpg
This is how my grid layout with 2 columns and 1 row would look like.
There are 3 items total inside

Blue square with yellow borders in 0, 0
Blue square with yellow borders in 1, 0
Green circle in 0, 0 - as you can see it's not above the square nor below, etc. it's overlapping the square.

Lykurg
16th February 2010, 18:12
Yeah, I could do that with fix size... but, how do I get the widths of the columns or rows to determine which one is the widest?
QGraphicsGridLayout::itemAt() => QGraphicsLayoutItem::geometry()



Here is the image mockup
http://filebeam.com/45d50e19c602345995313fb66c666bcf.jpg
This is how my grid layout with 2 columns and 1 row would look like.
There are 3 items total inside

Blue square with yellow borders in 0, 0
Blue square with yellow borders in 1, 0
Green circle in 0, 0 - as you can see it's not above the square nor below, etc. it's overlapping the square.

Ah, you are talking about graphic items not layout items... So there is no problem: arrange the three items in a QGraphicsItemGroup, then they behave like one item.

Palmik
16th February 2010, 18:21
QGraphicsGridLayout::itemAt() => QGraphicsLayoutItem::geometry()
You are right, that should do it :)



Ah, you are talking about graphic items not layout items... So there is no problem: arrange the three items in a QGraphicsItemGroup, then they behave like one item.
This should work :)
I have one more and hopefully last question. If I create QGraphicsItemGroup of 2 items which are inheriting both from QGraphicsSvgItem and QGraphicsLayoutItem (which should give it the capabily to be added to QGraphicsLayouts) I will have to reimplement the QGraphicsItemGroup so that it inherits from QGraphicsLayoutItem as well to be able to add it to QGraphicsLayout, would not I (not that it would much of a problem... but still :))?