PDA

View Full Version : Need Listbox with Columns - which component?



scintillion
8th April 2010, 00:54
I have numerous applications for a simple columnated listbox, but cannot figure out which QT4 component is best for this purpose (preferably one that I can place using QT Designer).

For example, I want to show a box like:

NAME ADDRESS PHONE
John Smith 123 First St 123-1341
Fred Smoot 234 Second St 234-4567

etc.

I have looked at some components such as TableWidget but not quite clear that is designed for my purpose (which does NOT involve the user needing to edit individual fields like a spreadsheet). I would like the user to be able to click on (and probably highlight) a line of his choice, however.

Thanks.


Victor

waynew
8th April 2010, 02:04
I'm not a Qt expert, but I don't think what you want is possible. If the data in a line is going to be separated, it would have to be edited separately because it would be stored in separate widgets.
Why do you need the data in columns, is it just for the visible effect? If that is the case, then you could use QTextEdit and separate the data programatically into the appearance of columns.

Maybe a real Qt expert will have a better answer.

scintillion
8th April 2010, 03:33
Well, primarily for visual effect, but also functional. The items in a single line belong together, in this example, and I do not need to edit them separately.

Using Delphi/Lazarus/FreePascal, I accomplished this function with a user designed TListBox component that would draw separate items in the separate columns (with an attached header to give the "names" of the columns at the top).

I was hoping to handle this with a single component under QT. It looks like a TableView widget has some of the capabilities I need, and there is mention of a "QStringListModel" which seems to suit my need for multiple strings in a line. However, it looks like it implements individual cells which is not really needed for my purpose.

I would be happy to have a component that could do the following, with 3 separate columns:

NAME ADDRESS PHONE
John Smith 123 First Street 132-1234

(Preferably having the column headers and the data columns from the list lined up automatically).

borisbn
8th April 2010, 04:44
You can still use QListView (or QListWidget) and make "columns" by justifying (http://qt.nokia.com/doc/4.6/qstring.html#leftJustified) your strings and header