PDA

View Full Version : QFileDialog and subclassing



mickey
17th April 2006, 22:38
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?


QFileDialog fd;
myFileDialog myFd(this,"");
QString file;
//myFd.show();
file = myFd.getOpenFileName(dir,
"All Files (*.jpg; *.png; *.pcx)",
this,
"open file dialog",
tr("Choose a texture"));

Chicken Blood Machine
18th April 2006, 08:17
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:

file = myFd.getOpenFileName(dir,
"All Files (*.jpg; *.png; *.pcx)",
this,
"open file dialog",
tr("Choose a texture"));
Is valid code, but is meaningless, it should be:

file = QFileDialog::getOpenFileName(dir,
"All Files (*.jpg; *.png; *.pcx)",
this,
"open file dialog",
tr("Choose a texture"));

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.

Cutey
18th December 2006, 14:48
Hi,

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

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

Thanks in advance.

jpn
18th December 2006, 15:10
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)

lauranger
18th December 2006, 15:15
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

Qt Coder
17th August 2009, 08:47
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????