Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Why QFileDialog::getOpenFileName is not centered?

  1. #1
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Smile Why QFileDialog::getOpenFileName is not centered?

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    This is strange.
    Can you post the piece of your code where you call QFileDialog::getOpenFileName?
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    Sure:

    Qt Code:
    1. void CEditor::OpenLevel() {
    2. QString filename_and_folder=QFileDialog::getOpenFileName(this, "Load Level", QString(LEVELS_FOLDER), "Unprocessed Level (*.xml);;All files (*.*)");
    3. ...
    4. }
    To copy to clipboard, switch view to plain text mode 

    CEditor is derived from QMainWindow

    Any idea? Am I missing anythig?

    Thanks.

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    Sorry! The only idea was that the pointer passed as QFileDialog's parent was NULL.

    Maybe it's a bug.
    Last edited by mcosta; 28th July 2009 at 11:07. Reason: updated contents
    A camel can go 14 days without drink,
    I can't!!!

  5. #5
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    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?

  6. #6
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    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.

  7. #7
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    Quote Originally Posted by Boron View Post
    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.

  8. #8
    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: Why QFileDialog::getOpenFileName is not centered?

    Doesn't it depend on your system settings? Do dialogs in other applications (non-Qt) open themselves centered above their parents?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    Quote Originally Posted by wysota View Post
    Doesn't it depend on your system settings?
    I don't know, I don't think so. Is Any Qt expert over there?


    Quote Originally Posted by wysota View Post
    Do dialogs in other applications (non-Qt) open themselves centered above their parents?
    Of course, I guess my windows is working nicely.

    Thanks

  10. #10
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    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.

  11. #11
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    Quote Originally Posted by Boron View Post
    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.

  12. #12
    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: Why QFileDialog::getOpenFileName is not centered?

    But it is nothing you can control from Qt... Qt only calls a native function.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    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.

  14. #14
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    Quote Originally Posted by wysota View Post
    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.

  15. #15
    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: Why QFileDialog::getOpenFileName is not centered?

    Quote Originally Posted by ricardo View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    Quote Originally Posted by wysota View Post
    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.

  17. #17
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    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.

  18. #18
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    Quote Originally Posted by Boron View Post
    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!
    Last edited by ricardo; 28th August 2009 at 17:36.

  19. #19
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    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

  20. #20
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why QFileDialog::getOpenFileName is not centered?

    Quote Originally Posted by aamer4yu View Post
    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!

Similar Threads

  1. centered text label
    By djconnel in forum Qwt
    Replies: 5
    Last Post: 28th April 2009, 17:22
  2. [Qt4]: Adding centered items in QListWidget
    By Jojo in forum Qt Programming
    Replies: 4
    Last Post: 16th March 2006, 20:04

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.