[Qt-jambi-interest] QTreeModel with several columns

Tom Schindl listom at bestsolution.at
Tue Dec 22 20:26:07 CET 2009


Hi Helge,

Not sure if this of interest for you but I've written my own MVC-Wrapper
around structured controls like List, Table, Tree, TreeTable.

And my setup looks like this:

--------8<--------
TreeTableViewer viewer
  = new TreeTableViewer<Person, Collection<Person>>(widget);

column = new TreeViewerColumn<Person>(viewer,"Location");
column.setLabelConverter(new LabelConverter<Person>() {
  @Override
  public String getText(Person element) {
    return element.getLocation();
  }
});

column = new TreeViewerColumn<Person>(viewer,"Birthday");
column.setLabelConverter(new LabelConverter<Person>() {
  @Override
  public String getText(Person element) {
    return element.getBirthday() != null ?
     SimpleDateFormat.getDateInstance().format(element.getBirthday())
     :"";
  }
});

viewer.setContentProvider(
   new ITreeContentProvider<Person, Collection<Person>>() {

   // ...

   public Collection<Person> getChildren(Person parentElement) {
     return parentElement.getFriends();
   }

   public boolean hasChildren(Person element) {
     return element.getFriends().size() > 0;
   }
});

viewer.setInput(book.getPeople());
--------8<--------

All the code is available under EPL from
https://dev.eclipse.org/svnroot/eclipse/org.eclipse.ufacekit/develop/eclipse/virtual-structure/incubation/org.eclipse.ufacekit.ui.qt.jface.

Tom

Am 22.12.09 18:38, schrieb Helge Fredriksen:
> Yes, that would be great! Thanks.
> 
> Helge
> 
> Robert Lebel wrote:
>> Hi,
>>
>> I did it by implementing QAbstractTableModel (and did not find it that
>> easy). I can send you the complete source of my model if you need it.
>>
>> public Object data(QModelIndex index, int role) {
>>
>>   ...
>>   switch (role) {
>>     case ItemDataRole.DisplayRole:
>>        switch (index.column()) {
>>        case 0:
>>          return "text column 1"
>>
>>        case 1:
>>          return "text column 2"
>>                         
>>
>>
>> 2009/12/22 Helge Fredriksen <hf at poseidon.no <mailto:hf at poseidon.no>>
>>
>>     Hello!
>>
>>     Anyone have any experience with implementing a QTreeModel with several
>>     columns? It seems possible to override the columnCount(QModelIndex)
>>     method to return 2, but I can't seem to find a way to control the text
>>     shown in column nr. 2 which I really would like to. It seems to
>>     replicate the text in both columns pr. default.
>>
>>     Do I need to implement the QAbstractTableModel to do this, or can
>>     I use
>>     the QTreeModel in some way?
>>
>>     Helge
>>     _______________________________________________
>>     Qt-jambi-interest mailing list
>>     Qt-jambi-interest at trolltech.com
>>     <mailto:Qt-jambi-interest at trolltech.com>
>>     http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest
>>
>>
> 
> 
> 
> _______________________________________________
> Qt-jambi-interest mailing list
> Qt-jambi-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest




More information about the Qt-jambi-interest mailing list