List Info

Thread: Displaying a table




Displaying a table
country flaguser name
Australia
2007-06-20 01:40:28
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.

_______________________________________________
kde-games-devel mailing list
kde-games-develkde.org
https://mail.kde.org/mailman/listinfo/kde-games-devel

Re: Displaying a table
user name
2007-06-20 02:21:43


2007/6/20, Ian Wadham < ianw2optusnet.com.au">ianw2optusnet.com.au>:

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?

Hi Ian!

QFontMetrics can give you a text's width and height.

Guid
Re: Displaying a table
country flaguser name
United States
2007-06-20 22:33:22
Ian Wadham wrote:
> [snip]
> I have tried QTreeWidgetItem::setSizeHint() but it
seems to be
> ignored, no matter when or where in the dialog
execution I use
> it.

KColorDialog had problems with QTableWidget, maybe you are
running into 
something similar? You could try using
QHeaderView::resizeSection instead.

-- 
Mathew
(sorry, .sig file is on the other computer)

_______________________________________________
kde-games-devel mailing list
kde-games-develkde.org
https://mail.kde.org/mailman/listinfo/kde-games-devel

Re: Displaying a table
country flaguser name
Australia
2007-06-21 01:49:05
On Thu, 21 Jun 2007 01:33 pm, Matthew Woehlke wrote:
> KColorDialog had problems with QTableWidget, maybe you
are running into
> something similar? You could try using
QHeaderView::resizeSection instead.
>
Hole in one, Matthew!   And
thanks for the QFontMetrics tip, Guillaume.

It seems that QHeaderView controls the whole column-sizing
(or
row-sizing) thing.  The following will make an entire column
of a tree
or table set its size to hold and display whatever data is
in column
N, except that the user can no longer resize it.

  tree->header()->setResizeMode (N,
QHeaderView::ResizeToContents);

QHeaderView::resizeSection would give even finer control
over the
data display.  Thanks, guys!  I had been looking for days in
the
wrong places.

All the best, Ian W.
_______________________________________________
kde-games-devel mailing list
kde-games-develkde.org
https://mail.kde.org/mailman/listinfo/kde-games-devel

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )