Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, September 2006
Setting up a scrollable list


Message 1 in thread

Hello again,

I'm struggeling a bit to get my QListWidget scrollable so that it fills 
the scroll area when I resize.
I've tried the following:

<snip>
list = new QListWidget();
QScrollArea scroller = new QScrollArea();
scroller.setWidget(list);
</snip>

but the list stay the same size (inside the scrollarea) when I resize. 
Do I need
to add some layout code inside here somewhere?

Regards,
Helge Fredriksen


Message 2 in thread

As far as I know the listWidget already add scrollbars itself so it has the 
size of the content and never just based on the window size (which IMO would 
be wrong).

I'm not sure why you try to do this.  It would be my understanding that just 
using the widget as is will give the behavior that's normal.

Maybe you can explain your usecase a little more since I'm thinking you are 
solving your problem a bit to complex :)


On Thursday 14 September 2006 14:02, Helge Fredriksen wrote:
> I'm struggeling a bit to get my QListWidget scrollable so that it fills
> the scroll area when I resize.
> I've tried the following:
>
> <snip>
> list = new QListWidget();
> QScrollArea scroller = new QScrollArea();
> scroller.setWidget(list);
> </snip>

-- 
 [ signature omitted ] 

Attachment: pgp68hNu0VjEG.pgp
Description: PGP signature


Message 3 in thread

Helge Fredriksen wrote:
> Hello again,
> 
> I'm struggeling a bit to get my QListWidget scrollable so that it fills 
> the scroll area when I resize.
> I've tried the following:
> 
> <snip>
> list = new QListWidget();
> QScrollArea scroller = new QScrollArea();
> scroller.setWidget(list);
> </snip>
> 
> but the list stay the same size (inside the scrollarea) when I
> resize. Do I need to add some layout code inside here somewhere?

Hi Helge,

As also pointed out by Thomas, this appraoch is wrong. Qt works 
differently than swing with regards to how these kind of components are 
built together. In Qt, we try to provide more selfcontained compoenets, 
meaning that components that you often (if not always) end up putting 
scrollbars on will have that functionality built in.

The proper way of setting up a list widget is simply:

list = new QListWidget

We believe that if a cerain pattern of code shows up for every time you 
use a widget, then that pattern belongs in the library ;-)

This is also illustrated with the various table examples I've posted on 
this list, and also with the TextEdit demo, with the scrollable text field.

-

In the cases where a scrollbar is not enough you can set the scrollbar 
policy to be turned off, individually for x and y if needed.

http://doc.trolltech.com/4.2/qabstractscrollarea.html#horizontalScrollBarPolicy-prop
http://doc.trolltech.com/4.2/qabstractscrollarea.html#verticalScrollBarPolicy-prop

If you want your widget to have a specifed size or resize behaviour you 
need to put it into a layout and possibly reimplement the sizeHint() and 
tweak its size policies.

http://doc.trolltech.com/4.2/qwidget.html#sizeHint-prop
http://doc.trolltech.com/4.2/qwidget.html#sizePolicy-prop

The simples way to get familiar with these is to play around with them 
in designer.

Use of layouts are also illustrated in all our examples.

-

best regards,
Gunnar