PDA

View Full Version : Why QFileDialog::getOpenFileName is not centered?



ricardo
27th July 2009, 20:28
Hi friends!

Do you know why QFileDialog::getOpenFileName is shown not centered? When I call it, I pass my QMainWindow derived class pointer, but all my open dialogs are wrong, however, my own dialogs that derive from qdialog, are always centered.

Any idea?

Thanks in advance.

mcosta
28th July 2009, 08:06
This is strange.
Can you post the piece of your code where you call QFileDialog::getOpenFileName?

ricardo
28th July 2009, 10:35
Sure:



void CEditor::OpenLevel() {
QString filename_and_folder=QFileDialog::getOpenFileName(t his, "Load Level", QString(LEVELS_FOLDER), "Unprocessed Level (*.xml);;All files (*.*)");
...
}


CEditor is derived from QMainWindow

Any idea? Am I missing anythig?

Thanks.

mcosta
28th July 2009, 11:01
Sorry! The only idea was that the pointer passed as QFileDialog's parent was NULL.

Maybe it's a bug.

ricardo
28th July 2009, 11:15
Using the debugger, "this" has a correct value.

And I read this on docs
http://doc.trolltech.com/4.5/qfiledialog.html
This function creates a modal file dialog with the given parent widget. If parent is not 0, the dialog will be shown centered over the parent widget.

What's going on? Perhaps because I'm using a static call?

Boron
28th July 2009, 12:15
The documentation on QFileDialog::getOpenFileName() says that the method, which is static, uses a native file dialog under Windows and not a QFileDialog.
This native dialog doesn't seem to be able to be opened centred in a Qt application.

ricardo
28th July 2009, 19:50
The documentation on QFileDialog::getOpenFileName() says that the method, which is static, uses a native file dialog under Windows and not a QFileDialog.
This native dialog doesn't seem to be able to be opened centred in a Qt application.

Are you telling that it is impossible to show that dialog centered?
It's difficult to believe. Can anyone tell me if he/she is having the same problem?

Thanks.

wysota
28th July 2009, 19:55
Doesn't it depend on your system settings? Do dialogs in other applications (non-Qt) open themselves centered above their parents?

ricardo
28th July 2009, 20:26
Doesn't it depend on your system settings?

I don't know, I don't think so. Is Any Qt expert over there?



Do dialogs in other applications (non-Qt) open themselves centered above their parents?

Of course, I guess my windows is working nicely.

Thanks

Boron
26th August 2009, 16:46
I just saw that QFileDialog::getOpenFileName(...) uses almost the same file dialog as Windows Notpad.
When using opening a file (menu File -> Open...) the dialog is not centered in Notepad. So the problem lies in Windows itself.

ricardo
27th August 2009, 13:55
I just saw that QFileDialog::getOpenFileName(...) uses almost the same file dialog as Windows Notpad.
When using opening a file (menu File -> Open...) the dialog is not centered in Notepad. So the problem lies in Windows itself.

Yes, you are right. But it would be nice to have a flag in order to select if you want to center that dialog, doesn't it? Maybe it is not possible because of Win32 API arquitecture, I don't know.

Does Qt have any list where I can suggest new features?


Thanks.

wysota
27th August 2009, 15:13
But it is nothing you can control from Qt... Qt only calls a native function.

Boron
27th August 2009, 17:36
How about writing a wrapper function that calls QFileDialog::getOpenFileName(..) and moves it to a centered position over the parent window?

This should require some windows library magic and a bit of mathematics.
But I really doubt it is worth the effort.

ricardo
27th August 2009, 19:28
But it is nothing you can control from Qt... Qt only calls a native function.

It is supposed Qt makes easier developers life, doesn't it?
Qt is not just a OS API wrapper.

wysota
27th August 2009, 21:35
It is supposed Qt makes easier developers life, doesn't it?
Qt is not just a OS API wrapper.

I really have no idea what you mean.

ricardo
28th August 2009, 15:29
I really have no idea what you mean.

Sorry, maybe my English is a bit strange.

I mean it is Qt which should center that dialog, not the developer.

Boron
28th August 2009, 16:14
According to your last post, we could also say that it is Microsoft that should center the dialog not Qt :).

But this doesn't lead to a solution. If none of the involved libraries or "systems" does the work we have to do the work ourselves or accept the default behaviour.

ricardo
28th August 2009, 17:31
According to your last post, we could also say that it is Microsoft that should center the dialog not Qt :).

But this doesn't lead to a solution. If none of the involved libraries or "systems" does the work we have to do the work ourselves or accept the default behaviour.

Qt goal is to make easier our lives. Microsoft... well...


By the way, is there any way to manually center that dialog? I don't remember any Win32 API method to do that.

Thanks!

aamer4yu
28th August 2009, 17:32
It is supposed Qt makes easier developers life, doesn't it?
Qt is not just a OS API wrapper.

Qt does makes life easier. But if it says that the static function calls native file dialog, why do u use it ? You can opt for the Qt file dialog. You only need not to call the static function :)

ricardo
28th August 2009, 17:37
Qt does makes life easier. But if it says that the static function calls native file dialog, why do u use it ? You can opt for the Qt file dialog. You only need not to call the static function :)

Don't understand you very well, do you mean create my own open file dialog from QDialog?

Thanks!

wysota
30th August 2009, 23:08
I mean it is Qt which should center that dialog, not the developer.

Why should Qt do that if it's the platform policy not to do that? As far as I remember my file dialogs are pretty centred. But then I'm working on a platform where it is a policy to centre dialogs.

When using the so called native dialog Qt is making a native call to the right API to provide a file dialog. It only cares about the basic options which are related to functionality of the dialog. If you want something else then either use the non-native dialog or make the native call (with appropriate options added) yourself.