Results 1 to 3 of 3

Thread: Model/View one index.column as hidden UserRole

  1. #1
    Join Date
    Jun 2007
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Model/View one index.column as hidden UserRole

    Hi

    I wanna switch from item-based QTreeWidget to model/view QTreeView.
    I have a 3-column-model. I need to display model-column 0 as Qt::UserRole of view-column 0, model-column 1 as Qt:isplayRole of view-column 0 and model-column 2 as Qt:isplayRole of view-column 1.

    Before in the treewidget i did it like this:
    Qt Code:
    1. item->setData(0, Qt::UserRole, index.column(0).toString());
    2. item->setData(0, Qt::DisplayRole, index.column(1).toString());
    3. item->setData(1, Qt::DisplayRole, index.column(2).toString());
    To copy to clipboard, switch view to plain text mode 

    The model is build like this:

    Qt Code:
    1. void myLessonNotesModel::refresh()
    2. {
    3. setQuery("SELECT noteid, date, content FROM note ORDER BY date DESC");
    4. setHeaderData(0, Qt::Horizontal, QObject::tr("Datum"));
    5. setHeaderData(1, Qt::Horizontal, QObject::tr("Notiz"));
    6. }
    To copy to clipboard, switch view to plain text mode 

    Can anybody tell me how to connect the model columns to different view columns in different roles?

    Best regards
    Felix

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Model/View one index.column as hidden UserRole

    Reimplement the data() method and return proper data from within there. Reimplement columnCount() to report the proper number of columns. Alternatively implement a very simple proxy model based on QSortFilterProxyModel where you will do the same without touching your base model.

  3. #3
    Join Date
    Jun 2007
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Model/View one index.column as hidden UserRole

    Thx. I will try QSortFilterProxyModel.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.