Results 1 to 3 of 3

Thread: [Solved] Dynamically assign namefilter to FileDialog?

  1. #1
    Join Date
    Jun 2013
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default [Solved] Dynamically assign namefilter to FileDialog?

    Hello!

    I am trying to dynamically assign a namefilter to a FileDialog, but this does not seem to work at all.

    Qt Code:
    1. import QtQuick 2.2
    2. import QtQuick.Dialogs 1.1
    3.  
    4. FileDialog {
    5.  
    6. title: qsTr("Export to File")
    7. selectExisting: false
    8.  
    9. onVisibleChanged: {
    10. if(visible)
    11. nameFilters = ["Image files (*.jpg *.png)", "All files (*)"]
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    Obviously this is just a test case, in real life I need to determine the available plugins of my application at runtime and assign the nameFilters accordingly. If I add
    Qt Code:
    1. console.log(nameFilters)
    To copy to clipboard, switch view to plain text mode 
    after I set them, they show up just fine. So why does this fail I wonder?

    Best Regards
    Last edited by QphiuchuS; 13th November 2014 at 11:39.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamically assign namefilter to FileDialog?

    So you are saying that the change of nameFilters does not affect the already visible dialog?

    Maybe make the test more realistic by doing something you would do in the actual case?

    E.g. create a property somewhere that holds the list and then make a binding for nameFilters to that property.
    This property is then a placeholder for the property your C++ code will be exporting.

    Cheers,
    _

  3. #3
    Join Date
    Jun 2013
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dynamically assign namefilter to FileDialog?

    Thank you for your answer! I already tried to use a property:

    import QtQuick 2.2
    import QtQuick.Dialogs 1.1

    FileDialog {

    title: qsTr("Export to File")

    property var nameFilterList: []

    selectExisting: false
    nameFilters: nameFilterList

    onVisibleChanged: {
    if(visible)
    nameFilterList = ["Image files (*.jpg *.png)", "All files (*)"]
    }
    }
    It had the same effect (that is none). At first I used the realistic approach, that is, get a QStringList from my C++ model and assign it. When this failed I further simplified my approach and found that I could not assign anything dynamically.


    BUT: you just gave the correct hint! I should have assigned the namefilter *before* I show the whole friggin dialog! Thank you a lot!

    Before:
    Qt Code:
    1. exportDialog.open()
    To copy to clipboard, switch view to plain text mode 

    After:
    Qt Code:
    1. exportDialog.nameFilters = ["All Files (*.*)"]
    2. exportDialog.open()
    To copy to clipboard, switch view to plain text mode 

    Thanks again.

Similar Threads

  1. FileDialog SaveAs Feature?
    By jazz in forum Qt Quick
    Replies: 1
    Last Post: 26th June 2014, 08:43
  2. Replies: 1
    Last Post: 21st August 2013, 23:23
  3. Default filename in filedialog of Windows 7
    By Infinity in forum Qt Programming
    Replies: 0
    Last Post: 13th February 2013, 22:01
  4. Replies: 1
    Last Post: 5th May 2011, 03:47
  5. Open FileDialog showing Back of the Widget in Mac
    By shyam prasad in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2007, 06:33

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.