Results 1 to 6 of 6

Thread: QFileDialog and subclassing

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default QFileDialog and subclassing

    Hi, I'm trying to subclassing QFile dialog to change it; I tried this below; but I see that I must use 'myFd.show();' to see my change; with these two ways, Dialog apparence is different; and with 'show() it seems I can't retrieve 'file variabile' (Is there a way to obtain 'file' variabile using myFd.getOpenFileName??? I need set .pcx .jpg....). An hint?
    Qt Code:
    1. myFileDialog myFd(this,"");
    2. QString file;
    3. //myFd.show();
    4. file = myFd.getOpenFileName(dir,
    5. "All Files (*.jpg; *.png; *.pcx)",
    6. this,
    7. "open file dialog",
    8. tr("Choose a texture"));
    To copy to clipboard, switch view to plain text mode 
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog and subclassing

    Read the documentation very carefully here. getOpenFileName() is a static method that creates a native file dialog on platforms like Windows and OSX.

    When you subclass QFileDialog, you are subclassing the Qt QFileDialog, not the native one. Calling static methods like getOpenFileName() will have no other effect then showing the native dialog becasue they are static, they will not operate on your instance.

    In fact:
    Qt Code:
    1. file = myFd.getOpenFileName(dir,
    2. "All Files (*.jpg; *.png; *.pcx)",
    3. this,
    4. "open file dialog",
    5. tr("Choose a texture"));
    To copy to clipboard, switch view to plain text mode 
    Is valid code, but is meaningless, it should be:
    Qt Code:
    1. file = QFileDialog::getOpenFileName(dir,
    2. "All Files (*.jpg; *.png; *.pcx)",
    3. this,
    4. "open file dialog",
    5. tr("Choose a texture"));
    To copy to clipboard, switch view to plain text mode 

    Therefore, you must use show() or exec() to show your instance of a filedialog. I recomend exec() - that way, when the dialog has been closed, functions like selectedFiles(), selectedFilter(), etc. will return the correct value.
    Save yourself some pain. Learn C++ before learning Qt.

  3. #3
    Join Date
    Dec 2006
    Location
    Bangalore, India
    Posts
    38
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QFileDialog and subclassing

    Hi,

    In my application, sub window calls (QFileDialog::getOpenFileName)static method to display "Open" file dialog but it is showing modaless dialog.

    I need Modal & Window Native Dialog . Any help...

    Thanks in advance.
    WINNERS DON`T D DIFFERENT THINGS THEY D THINGS differently.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QFileDialog and subclassing

    What did you pass as "QWidget* parent" argument?

    QString QFileDialog::getOpenFileName(const QString& startWith = QString::null, const QString& filter = QString::null, QWidget* parent = 0, const char* name = 0, const QString& caption = QString::null, QString* selectedFilter = 0, bool resolveSymlinks = TRUE)
    J-P Nurmi

  5. #5
    Join Date
    May 2006
    Posts
    55
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileDialog and subclassing

    What do you need subclassing for ?
    As you require native dialog, it seems there is no way to do that.
    If you just need an open file dialog, just use the static method
    already mentioned in this thread.
    Regards

  6. #6
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFileDialog and subclassing

    Hello, I m using Qt 4.4.3

    I hav a similar query.


    I need a QFileDialog which has navigation buttons,create folder button disabled .

    So that user should be able to select file only from path which I would pass while initializing.

    For this I need to subclass QFileDialog .

    how to acheive this????

Similar Threads

  1. Add Widget to QFileDialog
    By Rayven in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2006, 18: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.