PDA

View Full Version : Native QFile Dialog



lumpy69
7th August 2017, 11:24
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.


import sys
from PyQt4 import QtGui
from PyQt4 import QtCore

class StartWindow(QtGui.QMainWindow):
def __init__(self):
# setting up my widget
super(StartWindow, self).__init__()

# add button to select workspace
self.workspace = None
button = QtGui.QPushButton('Select Workspace')
button.clicked.connect(self.__select_workspace)
self.setCentralWidget(button)

def __select_workspace(self):
dialog = QtGui.QFileDialog()
self.workspace = dialog.getExistingDirectory(self, 'Select folder',
options=QtGui.QFileDialog.ShowDirsOnly)
print(self.workspace)


def main():
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_ X11InitThreads)
app = QtGui.QApplication(sys.argv)
# setting up the style i want
app.setStyle("cleanlooks")
_ = StartWindow()
sys.exit(app.exec_())

if __name__ == '__main__':
main()

d_stranz
7th August 2017, 17:17
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:



self.workspace = QtGui.QFileDialog.getExistingDirectory(self, 'Select folder', options=QtGui.QFileDialog.ShowDirsOnly)

lumpy69
7th August 2017, 17:44
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.