Search code examples
pythonpython-3.xpyqt5pyinstaller

PyQT5 QFileDialog issues with Pyinstaller


I'm using PyQt5 with Pycharm and Python 3.7 on Arch Linux (also tried with 3.8). When I run my code from PyCharm or directly from the command line the file dialog opens fine. However, when I build with Pyinstaller I get consistent errors when using them. Code:

def choose_log_location(self):
    self.log_location = QFileDialog.getExistingDirectory(
        self,
        "Choose Log Files Directory",
        "/home",
        options=QFileDialog.ShowDirsOnly)

    if self.log_location != "":
        self.Log_Location.setText(self.log_location)

After building with Pyinstaller, running the built application and clicking the button that fires off this method I get 3 error dialogs pop up:

  1. Error ? URL cannot be listed file:///
  2. Malformed URL
  3. Error ? URL cannot be listed file:///

Then, once the filedialog actually pops up, the main area is blank.

Blank QFileDialog

I also get the following error in the console:

kf5.kio.core: "" qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 7952, resource id: 36398251, major code: 40 (TranslateCoords), minor code: 0

I also get somewhat similar issues using QFileDialog.getOpenFileName() (blank area where files should be - note tested without filter, same result) but a different error in the console:

kf5.kservice.services: KServiceTypeTrader: serviceType "ThumbCreator" not found

GetOpenFileName dialog


Solution

  • I had the same problem. It seems that pyinstaller produces this errors with native dialogs. So my solution is to use the DontUseNativeDialog option.

    e.g.

    self.log_location = QFileDialog.getExistingDirectory(
            self,
            "Choose Log Files Directory",
            "/home",
            QFileDialog.DontUseNativeDialog)