Results 1 to 2 of 2

Thread: QListView and QStringListModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,330
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QListView and QStringListModel

    How can I do it? I would have an help on it.
    Derive a custom model from QStringListModel, and override the data() method. In the handler for DisplayRole, use QFileInfo to retrieve the file name only from the path (using QFileInfo::fileName()) and return that as the QVariant. For all other data roles, call the QStringListModel base class data() method.

    For your processing where you need the entire path, you can implement a handler for Qt::UserRole in your custom model. For that role, you call the base class data() method with the Qt::DisplayRole role, which will return the entire path string. In your list-handling code, you would call into the model with the UserRole when you need the full path.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. The following user says thank you to d_stranz for this useful post:

    franco.amato (7th December 2019)

Similar Threads

  1. QML Combobox with QStringListModel
    By volcano in forum Qt Quick
    Replies: 3
    Last Post: 29th November 2016, 06:59
  2. Replies: 1
    Last Post: 3rd September 2013, 19:47
  3. Replies: 4
    Last Post: 7th March 2013, 16:20
  4. QListView
    By Yayati.Ekbote in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2010, 18:50
  5. QListView
    By moowy in forum Qt Programming
    Replies: 2
    Last Post: 2nd October 2006, 14:14

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
  •  
Qt is a trademark of The Qt Company.