Results 1 to 5 of 5

Thread: QFileDialog: how to choice File or Directory in the same Dialog

  1. #1
    Join Date
    Sep 2006
    Posts
    20
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question QFileDialog: how to choice File or Directory in the same Dialog

    Hallo!
    Can I coice a File or a Directory in the same file dialog?
    QFileDialog fd(this);
    fd.setFileMode( QFileDialog:irectory); //I can choice only directories
    fd.setFileMode( QFileDialog::AnyFile); //If I select the directory and press Ok, i don't leave the Dialog but go to this directory

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog: how to choice File or Directory in the same Dialog

    It would be hard to create a combined directory and file dialog. Much because it would be impossible to tell if you pick a directory or just want so enter it to look for other directories or files.

  3. #3
    Join Date
    Sep 2006
    Posts
    20
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog: how to choice File or Directory in the same Dialog

    My idee is to change to the directory by pressing Enter or clicking (Focus on the directory) and to pick a directory or a file with the Pushbutton Ok (Clickingwith the mouse on the pushbutton or pressing Enter as the focus is on the pushbutton).

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFileDialog: how to choice File or Directory in the same Dialog

    You can use QDirModel to implement your own file chooser or subclass QFileDialog and change it according to your needs.

  5. #5
    Join Date
    Sep 2006
    Posts
    20
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog: how to choice File or Directory in the same Dialog

    Quote Originally Posted by illojal
    i found a thread where you needed QFileDialog to being able to select files and dirs and im in the exact same situation now so i wonder if you ever made such a dialog. I would be really glad if you could share it with me.
    BUFileDia.h

    #ifndef _BUFILEDIALOG_H_
    #define _BUFILEDIALOG_H_
    #include <QFileDialog>
    class BUFileDialog: public QFileDialog
    {
    public:
    BUFileDialog ( QWidget * parent, Qt::WindowFlags flags ):QFileDialog(parent,flags){}
    BUFileDialog ( QWidget * parent = 0, const QString & caption = QString(), const QString & directory = QString(), const QString & filter = QString() ):
    QFileDialog ( parent ,caption,directory,filter){}
    public slots:
    void accept ();


    };
    #endif

    BUFileDia.cpp
    #include "BUFileDialog.h"

    void BUFileDialog::accept()
    {
    QStringList files = selectedFiles();
    if (files.isEmpty())
    return;
    emit filesSelected(files);
    QDialog::accept();
    }

Similar Threads

  1. errors while installing Qt4.2 in Linux
    By nimmyj in forum Installation and Deployment
    Replies: 11
    Last Post: 13th December 2006, 11:58
  2. Replies: 4
    Last Post: 24th February 2006, 10:30
  3. create file in another directory
    By raphaelf in forum Qt Programming
    Replies: 3
    Last Post: 16th February 2006, 10:04
  4. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54
  5. 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.