QHeaderView

Robert Knight robertknight at gmail.com
Sun Jan 18 02:51:59 GMT 2009


>  Any suggestions on how to proceed?  If other people agree with me,
> perhaps we can get a patch into Qt to allow for this behaviour.

The goal is to keep the content in each column readable when resizing
the sections.  This requires some input to the header view about the
minimum width for each column and also an 'aesthetically pleasant'
distribution of widths between them.  For a commercial project* I
implemented a 'stretchy' header view widget which sets the initial
sizes based on ratios between the various sections and then adjusts
the proportions, rather than the actual widths, when the user resizes
columns.  This is pretty much the same as the 'stretch factor' concept
which Qt layouts have.  This means that:

- Most importantly, the default column widths can be set for each
column in a way which
works with different screen and font sizes
- It keeps a decent amount of the content visible when resizing but
prevents columns being undesirably squished

Implementation attached.  To use it, replace the existing QHeaderView
widgets in the tableview with a StretchHeaderView instance and then
call header->setStretchFactor() for each column to set ratios between
QHeaderView columns.  Works the same way as setStretchFactor() in Qt
layouts.

Regards,
Robert.

* see www.mendeley.com

2009/1/18 John Tapsell <johnflux at gmail.com>: Any suggestions on how to
proceed?  If other people agree with me,
perhaps we can get a patch into Qt to allow for this behaviour.

> Hi all,
>
>  It's very difficult for a user to use a QHeaderView.  Press ctrl+esc
> to bring up the task manager thing, then try to enlarge, say, the CPU
> column.  Doing so shrinks the column next to, so the user then has to
> enlarge that column to fix it.  Then the user has to fix the column
> next to _that_, and so on.  Trying to englarge a single column
> requires about 5 operations!
>
>  Shrinking a column has a different behaviour though - it causes the
> last column (set to stretch) to grow.  So if you just enlarge the CPU
> column then shrink it again back to its original size, you then have
> to do about 5 operations to fix the size of all the other columns
> again.
>
>  I think the ideal behaviour is that both grow and shrink should
> shrink/grow the last stretched column only.
>
>  Dolphin implements this behaviour by reimplementing QHeaderView, but
> Peter Penz says that this took a lot of work to do.
>
>  Any suggestions on how to proceed?  If other people agree with me,
> perhaps we can get a patch into Qt to allow for this behaviour.
>
>
> JohnFlux
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: StretchHeaderView.h
Type: text/x-chdr
Size: 3340 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090118/8c04ac44/attachment.h>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: StretchHeaderView.cpp
Type: text/x-c++src
Size: 6031 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090118/8c04ac44/attachment.cpp>


More information about the kde-core-devel mailing list