Qt-interest Archive, January 2007
Layout Problem
Message 1 in thread
Hi,
Qt4.1.2
I have to layout some widgets(pushbuttons,labels) on a Frame
The requirement is such that they are divided in to two blocks:
_________
_________
| | space
| |
|widgets |
<---------------------------------------------------->|widgets |
|_________|
|_________|
So basiaclly one set of widgets at left side and other set at right side
of main window.
I have one Grid Layout for Left set of widgets, Second GridLayout for
Right set of widgets. Then I take a outer Grid Layout and add space
between them like this:
OuterGrid->addLayout(LeftGridlayout,0, 0, 1, 1)
spacerItem1 = new QSpacerItem(100, 20, QSizePolicy::Expanding,
QSizePolicy::Minimum);
OuterGrid->addItem(spacerItem1);
OuterGrid->addLayout(RightGridlayout,0, 2, 1, 1)
The problem is no matter what I set the size of spacer,it doesnot expand
and I have Left and Right set of widgets like this:
_________ _________
| | space | |
<--------->|widgets |<------------>|widgets |<--------->
|_________| |_________|
How can I set the spacer to take maximum space between left and right
set of widgets. As seen above I have set the horizontal strech policy
to: QSizePolicy::Expanding
Thanks.
--
[ signature omitted ]
Message 2 in thread
On 11.01.07 14:51:53, Jaya Meghani wrote:
> Hi,
>
> Qt4.1.2
>
> I have to layout some widgets(pushbuttons,labels) on a Frame
> The requirement is such that they are divided in to two blocks:
> _________
> _________
> | | space
> | |
> |widgets |
> <---------------------------------------------------->|widgets |
> |_________|
> |_________|
>
>
>
> So basiaclly one set of widgets at left side and other set at right side
> of main window.
>
> I have one Grid Layout for Left set of widgets, Second GridLayout for
> Right set of widgets. Then I take a outer Grid Layout and add space
> between them like this:
Have you tried a QHBoxLayout as outer layout? I see no reason for a
QGridLayout here and it may actually be the reason. If I'm not mistaken
the GridLayout is makeing all 3 columns the same size and places the
contents centered in it.
Andreas
--
[ signature omitted ]
Message 3 in thread
Thanks,But I am using Grid Layout because there is a chance that in
future more widgets can be added.
> -----Original Message-----
> From: Andreas Pakulat [mailto:apaku@xxxxxx]
> Sent: Thursday, January 11, 2007 2:58 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: Layout Problem
>
> On 11.01.07 14:51:53, Jaya Meghani wrote:
> > Hi,
> >
> > Qt4.1.2
> >
> > I have to layout some widgets(pushbuttons,labels) on a Frame The
> > requirement is such that they are divided in to two blocks:
> > _________
> > _________
> > | | space
> > | |
> > |widgets |
> > <---------------------------------------------------->|widgets |
> > |_________|
> > |_________|
> >
> >
> >
> > So basiaclly one set of widgets at left side and other set at right
> > side of main window.
> >
> > I have one Grid Layout for Left set of widgets, Second
> GridLayout for
> > Right set of widgets. Then I take a outer Grid Layout and add space
> > between them like this:
>
> Have you tried a QHBoxLayout as outer layout? I see no reason
> for a QGridLayout here and it may actually be the reason. If
> I'm not mistaken the GridLayout is makeing all 3 columns the
> same size and places the contents centered in it.
>
> Andreas
>
> --
> You are a bundle of energy, always on the go.
>
> --
> To unsubscribe - send a mail to
> qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the
> subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
--
[ signature omitted ]
Message 4 in thread
On 11.01.07 15:19:29, Jaya Meghani wrote:
> Thanks,But I am using Grid Layout because there is a chance that in
> future more widgets can be added.
Well, then there's no way to achieve what you want. Another way would be
to use a hbox layout for these 3 things and put that into the grid
layout.
Andreas
--
[ signature omitted ]
Message 5 in thread
> On 11.01.07 15:19:29, Jaya Meghani wrote:
> > Thanks,But I am using Grid Layout because there is a chance that in
> > future more widgets can be added.
>
> Well, then there's no way to achieve what you want. Another
> way would be to use a hbox layout for these 3 things and put
> that into the grid layout.
>
Will try that thanks.
Also I have a pushbutton in one (Left) Grid layout. Caption of that
changes at run time. So I need to change the size of button.
When itry to change the size of button nothing happens.
I tried resize() and adjustSize() but button just wont expand.
Any ideas on this?
Thanks
> Andreas
--
[ signature omitted ]
Message 6 in thread
On Thursday 11 January 2007 22:12, Jaya Meghani wrote:
> Also I have a pushbutton in one (Left) Grid layout. Caption of that
> changes at run time. So I need to change the size of button.
> When itry to change the size of button nothing happens.
You could calculate a sizeHint based on the length of the longer piece of text
and use this in a re-implemented sizeHint() for the widget.
A
--
[ signature omitted ]
Message 7 in thread
> On Thursday 11 January 2007 22:12, Jaya Meghani wrote:
>
> > Also I have a pushbutton in one (Left) Grid layout. Caption of that
> > changes at run time. So I need to change the size of button.
> > When itry to change the size of button nothing happens.
>
> You could calculate a sizeHint based on the length of the
> longer piece of text and use this in a re-implemented
> sizeHint() for the widget.
>
I used that way thanks much.
Now the button is able to resize based on the text it contains.
However that has created another one.
I have a small pushbutton next to expanding button like this:
______ _
|______| |_|
A B
1). Now when A expands B doesnot appropriately move with it and is
sometimes overlapping with button A, Like this:
__________ _
|__________||_|
A B
2). On the other hand when A shrinks, B doesnot come closer to A:
__ _
|__| |_|
A B
I want the distance between A and B to be constant. How can I achieve
that. I have done numerous trails but no luck.
Thanks.
--
[ signature omitted ]
Message 8 in thread
n 1/11/07, Jaya Meghani <Jaya.Meghani@xxxxxxxxxx> wrote:
> OuterGrid->addLayout(LeftGridlayout,0, 0, 1, 1)
> spacerItem1 = new QSpacerItem(100, 20, QSizePolicy::Expanding,
> QSizePolicy::Minimum);
> OuterGrid->addItem(spacerItem1);
> OuterGrid->addLayout(RightGridlayout,0, 2, 1, 1)
>
> The problem is no matter what I set the size of spacer,it doesnot expand
> and I have Left and Right set of widgets like this:
>
> _________ _________
> | | space | |
> <--------->|widgets |<------------>|widgets |<--------->
> |_________| |_________|
>
>
> How can I set the spacer to take maximum space between left and right
> set of widgets. As seen above I have set the horizontal strech policy
> to: QSizePolicy::Expanding
As Andreas said, try a QHBoxLayout:
QHBoxLayour* outer = new QHBoxLayout;
outer->addLayout(LeftGridlayout);
outer->addStretch();
outer->addLayout(RightGridlayout);
setLayout(outer);
--
[ signature omitted ]