PDA

View Full Version : How do I move a widget inside a grid Layout



barnabyr
8th May 2006, 23:06
Hello !

I have a QFrame that has a QGridLayout. In grid cell 0,0 I have a QLabel
that is left aligned and in cell 0,1 I have a QLabel that is right aligned.

This frame is initially raised but I have it set up so you can click the
frame and it will become sunken.

When the frame switches to sunken I want to shift the QLabel in cell 0,0 a little
bit to the right and down like buttons usually do. (aside: Maybe I could shift the
whole grid but I was thinking the right aligned label in (0,1) might get clipped by
the right edge.)

OK so I tried the obvious .. saving the initial position of the QLabel
when the frame is constructed with the line

m_pInitialTitlePos = m_lblAssetTitle->pos();

and then coding the below when I process the change in the frame's appearance ...



if (state)
{
setFrameStyle(QFrame::Panel | QFrame::Raised);
m_lblAssetTitle->move(m_pInitialTitlePos);
}
else
{
setFrameStyle(QFrame::Panel | QFrame::Sunken);
m_lblAssetTitle->move(m_pInitialTitlePos + QPoint(10,10));
}


but that does nothing.

I am obviously way off on this one .. what is the right way to do things ?

Thank you

barnaby

wysota
8th May 2006, 23:23
Basically move() won't work because the layout won't allow it to. If you use layouts, you can't move widgets around. You are trying to do a very strange thing... You should either use buttons instead of labels (so that they behave like buttons, like you want them to) or subclass QLabel and implement the desired behaviour (shifting the contents) yourself. Or do both -- subclass one of button classes and implement your behaviour there.