[Kde-games-devel] Displaying a table

Ian Wadham ianw2 at optusnet.com.au
Wed Jun 20 08:40:28 CEST 2007


I have just committed the start of some changes to the dialog the
selects games and levels in KGoldrunner.  The same dialog also
comes up automatically as the app starts.  It inherits from KDialog
and was coded manually several years ago.

What I am trying to do is present a multi-column list of all the
games, with columns for name of game, rules, number of levels
and skill level.  Previously it was a single-column list.  I have
used QTreeWidget and QTreeWidgetItem to get the multi-
column list and handle selections.  But now I am stuck ... :-(

The problem is how to set the *widths* of the columns so as to
display as much of the text as possible.  I do not think the end
user should have to do this.  The best I can get for the name of
the game is "Name of Gam" in the column header and the actual
names severely truncated and with ellipsis (...).  All the columns
start at roughly the same width, regardless of the width of the
data displayed.  I would like a wider column for names and
narrower ones for other data.

I have tried QTreeWidgetItem::setSizeHint() but it seems to be
ignored, no matter when or where in the dialog execution I use
it.  I have also tried QTreeWidget::itemWidget(), then resizing the
underlying widget, but QTreeWidget::itemWidget() always returns
me a null pointer.

And I did read through all 11 chapters of Model/View Programming
and dabbled with subclassing a model and view, but it all became
too hard, particularly because my internal model uses names to
identify columns, rather than numbers (i.e. the underlying rows
are based on a class).

There must be some easy way to adjust column widths in the display
by program, so that the data presented is reasonably readable and
the user rarely has to resize the columns.

I appreciate that fonts and languages affect the required width, so
perhaps there is also somewhere some simple function that tells
us what size is required to display a piece of text in a given font,
translated into the current language.

Has anybody any ideas or pointers to example code?

Cheers, Ian W.



More information about the kde-games-devel mailing list