PDA

View Full Version : Can't change items aligment in QGraphicsLinearLayout



T4ng10r
22nd December 2009, 12:06
I create one QGraphicsWidget inside which in two columns I want to place circles.
So inside this widget tree layout are created. One main to store two vertical Layouts.



m_hbMainLayout = new QGraphicsLinearLayout(Qt::Horizontal);
vbLeftLayout = new QGraphicsLinearLayout(Qt::Vertical);
vbRightLayout = new QGraphicsLinearLayout(Qt::Vertical);

m_hbMainLayout->addItem(vbLeftLayout);
m_hbMainLayout->addItem(vbRightLayout);

if (layout())
delete layout();
setLayout(m_hbMainLayout);

Then I add circles by


vbLeftLayout->addItem(devGUIChild);
vbLeftLayout->setAlignment(devGUIChild,Qt::AlignVCenter);

But at the end circles aren't placed as I expect.
http://www.img-share.net/thumbnail/45Sim_Screen.JPG (http://www.img-share.net/uploads/45Sim_Screen.JPG)

Those circles should be placed vertically evenly and in the middle. Right ones are placed evenly, but the left one isn't placed in the middle.
This approach works fine when I work with normal widgets and layout. Could some one tell me how to fix it?

T4ng10r
28th December 2009, 10:33
After few investigations I find out that layout isn't taking his size from widget inside which his placed. Widget size is fixed to (60,120), while layout takes only (20,46) for him self. Two item placed inside are 20,20 in size, so layout takes only so much space to enclose this items.
Why layout isn't expanding? I set size policy for layout to QSizePolicy::MinimumExpanding, but it didn't help at all.

When items inside had set only minimum and preferred size (maximum wasn't set) - layout was taking as much space as possible. But items placement wasn't correct. Now when I set maximum size too - layout isn't expanding.

EDIT:
I couldn't find any good flexible solution. Even QT examples weren't helpful - in them item were placed by calculating position in paint() method. And this is what I did.
But, in my opinion. layout should place items spread evenly on entire available space.