Results 1 to 3 of 3

Thread: Native QFile Dialog

  1. #1
    Join Date
    Aug 2017
    Posts
    2
    Qt products
    Platforms
    Unix/X11

    Default Native QFile Dialog

    Hi guys,

    First i would like to apologize if my english is not perfect, it's not my native language.

    Second, Thank you in advance for the help u might provide here.

    Let me explain my problem. I design a GUI at work with pyQt4 in python3. The target environment is a fork from my company of debian stretch. But since debian 9 is quite recent, my company's fork is not available yet. So till the new OS version is released, the app i design will run in a chroot made to emulate the future environment.
    But in this chroot, the default style of Qt is quite ugly (windows 95 like ), so i set a style in my application launcher.

    This style is much more pretty than the original one. But with it I can't find a way to have a QFileDialog matching the system file explorer (which I have in default style)...
    I hope there is workaround to make me use the style I want and still have a QFileFDialog like the one in my system (nautilus).

    Here a simplified version of my code with only the part involved.
    Qt Code:
    1. import sys
    2. from PyQt4 import QtGui
    3. from PyQt4 import QtCore
    4.  
    5. class StartWindow(QtGui.QMainWindow):
    6. def __init__(self):
    7. # setting up my widget
    8. super(StartWindow, self).__init__()
    9.  
    10. # add button to select workspace
    11. self.workspace = None
    12. button = QtGui.QPushButton('Select Workspace')
    13. button.clicked.connect(self.__select_workspace)
    14. self.setCentralWidget(button)
    15.  
    16. def __select_workspace(self):
    17. dialog = QtGui.QFileDialog()
    18. self.workspace = dialog.getExistingDirectory(self, 'Select folder',
    19. options=QtGui.QFileDialog.ShowDirsOnly)
    20. print(self.workspace)
    21.  
    22.  
    23. def main():
    24. QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads)
    25. app = QtGui.QApplication(sys.argv)
    26. # setting up the style i want
    27. app.setStyle("cleanlooks")
    28. _ = StartWindow()
    29. sys.exit(app.exec_())
    30.  
    31. if __name__ == '__main__':
    32. main()
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Native QFile Dialog

    By default, Qt will use the native file dialog when one is available, so I am not sure why that is not happening in your case. You can look in the discussion of QFileDialog::Option and DontUseNativeDialog. You might have to derive a class from QFileDialog in order to get the behavior you want.

    I am not a python expert, but the methof you are calling: getExistingDirectory() is a static member function in C++. You do not need to create an instance of the QFileDialog class in order to use it. I think the same is true in python, so your code probably should be:

    Qt Code:
    1. self.workspace = QtGui.QFileDialog.getExistingDirectory(self, 'Select folder', options=QtGui.QFileDialog.ShowDirsOnly)
    To copy to clipboard, switch view to plain text mode 
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Aug 2017
    Posts
    2
    Qt products
    Platforms
    Unix/X11

    Default Re: Native QFile Dialog

    Thanks for the tips about the static method.

    I've already tried to use the DontUseNativeDialog option before, it doesn't work. I think the problem here is the chroot, which mess things.

Similar Threads

  1. qfile dialog error
    By SirJonas in forum Newbie
    Replies: 3
    Last Post: 2nd November 2016, 15:08
  2. Replies: 2
    Last Post: 6th May 2013, 08:06
  3. QFile dialog, native view
    By franco.amato in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2010, 04:15
  4. Canceling the getOpenFileName native dialog
    By mclark in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2009, 22:59
  5. Replies: 2
    Last Post: 4th February 2008, 11:00

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.