Results 1 to 3 of 3

Thread: Subclass QListView to show two colums in one

  1. #1
    Join Date
    Jun 2006
    Posts
    43
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Subclass QListView to show two colums in one

    I have two views connected to the same model. One is a QListView that shows all the rows, the other is a widget with column fields which I'll call my EditBox.

    I am attempting to subclass QListView and modify it's display. The default QListView implementation shows only the column specified by modelColumn(). Mine needs to combine two columns into one.

    "lastname, firstname"

    When I've asked people about tackling this, most answers are "modify the model". This is a display issue and the view really should handle this. Edits to the firstname or lastname fields will need to trigger a dataChanged() signal in the view, so duplicating the data storage is not preferred.

    My issue is knowing what to reimplement in QListView to override the display. Hopefully I can then dive into the model and pull out the required fields from the row specified by the index given (e.g. don't show lastname only, but go find firstname and append it to the end with a comma just before doing your layout). paint() is so low level. There's got to be a better place.

    I have read everything I could on delegates, but I am a bit confused if they handle the display as well as editing. This will have no editing in the QListView. It will be read-only.

    So, where should I look? View or Delegate?
    Does anyone have any examples? (The spin box example in the tutorials isn't much help)
    It should be pre-layout, obviously.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclass QListView to show two colums in one

    How about implementing a proxy model?

  3. #3
    Join Date
    Jun 2006
    Posts
    43
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclass QListView to show two colums in one

    I had considered this, but kept coming back to the "View/Model" format. From what I'm seeing in the QListView source code this isn't going to just be reimplementing a few member functions.

    Yes, this would probably be the cleanest solution from what I'm seeing.

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.