Results 1 to 6 of 6

Thread: QFileDialog and file sequences

  1. #1
    Join Date
    Aug 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QFileDialog and file sequences

    I need to create a version of QFileDialog that optionally concatentates numbered file sequences into a single entry. So it should combine
    image.0001.exr image.0002.exr image.0003.exr
    into
    image.%04d.exr [1-3]
    This string should be displayed in the file list and also be returned by QFileDialog::selectedFile() if it is chosen.

    I know in general how to scan a list of file names and turn it into a list of sequences, but I can't work how to do that in a QFileDialog.

    Any suggestions on how to do this? Can I use a QAbstractProxyModel to filter out all but the first file in each sequence? How can I change entries in a QFileDialog (so I can change "image.0001.exr" to "image.%04d.exr [1-3]")

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog and file sequences

    You can use the QFileDialog::fileSelected signal to see when the selection changes.
    This will pass to you a QStringList of selected files absolute paths.

    Next, you can use QFileDialog::setLabelText to modify the file name label with your custom name.

    I do not think you can actually make the file dialog return that string, but you can store it somewhere and use it afterwards.

    Regards
    Last edited by marcel; 12th August 2007 at 01:39.

  3. #3
    Join Date
    Aug 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFileDialog and file sequences

    OK - that's a start, but I still need to display sequences rather than individual files in the current directory view. Any ideas?

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog and file sequences

    The thing about QFileDialog is that it shows you files that already exist.
    The model underneath the view takes care of that.

    So, if you have image.0001.exr image.0002.exr image.0003.exr, you can't make it in any way to show image.%04d.exr [1-3] instead of those entries. Unless you create your own model and view.
    Practically a custom file dialog.

    EDIT: however, maybe you can do something with a custom delegate, but again, these operate on single items.

    Regards

  5. #5
    Join Date
    Aug 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFileDialog and file sequences

    OK - beginning to get there.

    I subclassed QSortFilterProxyModel and reimplemented QSortFilterProxyModel::filterAcceptsRow to check for other files in the sequence.

    Somehow QFileDialog::setProxyModel seems to have stopped selected files appearing in the File name LineEdit and I still haven't been able to change the filenames in the current directory view, but it's a start.

    EDIT: Seems that even doing
    Qt Code:
    1. QFileDialog::setProxyModel(new QSortFilterProxyModel() )
    To copy to clipboard, switch view to plain text mode 
    prevents files clicked on in the current directory view appearing as the selected file. Everything else seems to work. Any ideas?
    Last edited by peterhillman; 12th August 2007 at 09:39. Reason: updated contents

  6. #6
    Join Date
    Aug 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFileDialog and file sequences

    Problem solved - more or less, but it isn't very clean.

    • QT 4.3.2 fixes a bug with the FilterProxyModels which meant that selected files wouldn't appear in the line editor.
    • Since files don't pass through QSortFilterProxyModel::filterAcceptsRow in any predictable order, a list of files seen in each sequence is required to ensure only the one 'standin file' is accepted for each sequence.
    • The FileSystemModel doesn't support DisplayRoles (changing the text for the DisplayRole would be the neat way of getting the name of the sequence to display instead of the standin file) - a very ugly workaround was to create a displayDelegate and override displayText to draw the sequence name rather than the standin. Annoyingly, this approach means the sequence name can't be longer than the name of the standin.
    • A queued signal connection from changedSelection is required to display (via selectFile) the sequence name rather than the standin file when it's clicked.


    Not nice, not pretty, but it works.

Similar Threads

  1. How to read text only as it is from file
    By thomasjoy in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2007, 08:47
  2. Replies: 4
    Last Post: 13th June 2007, 15:37
  3. QFileDialog in Qt designer
    By tpf80 in forum Qt Tools
    Replies: 1
    Last Post: 17th May 2007, 00:41
  4. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 14:52

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.