Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Override default GUI and functionality of QFileDialog globally
Qt 6.11 is out! See what's new in the release blog

Override default GUI and functionality of QFileDialog globally

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 4 Posters 1.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mmiscool
    wrote on last edited by
    #1

    Hello,

    I am currently working with an open source aplication that uses the QtGui.QFileDialog.htm from PySide.
    https://doc.qt.io/qtforpython/PySide2/QtWidgets/QFileDialog.html

    This dialog is used hundreds of times in the application so manually replacing all instances is not really an option.

    I was hoping that there might be a way to override the current functionality of this dialog and replacing it with one of my own design. The one of my own design would talk to a server for its listing copy some files locally after a user selected them before allowing the application to continue normally.

    Any help would be great,

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      First thing: a good IDE would allow you to replace QFileDialog with your own class pretty easily and would be the right thing to do with regard to longterm maintenance and peace of mind.

      Now since it's python, you can apply some black magic. The brutal way to do it would be something like:

      import QtWidgets
      
      class MyCoolFileDialog(QtWidgets.QWidget):
          ....
      QtWidgets.QFileDialog = MyCoolFileDialog
      

      I am guessing that you might just be using one of the static method of QFileDialog, if that's the case, then just replace the static method rather that the whole class.

      The right term is monkey patching.

      You definitely want to put some warning somewhere about what you are doing here and document it properly.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      JonBJ 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        First thing: a good IDE would allow you to replace QFileDialog with your own class pretty easily and would be the right thing to do with regard to longterm maintenance and peace of mind.

        Now since it's python, you can apply some black magic. The brutal way to do it would be something like:

        import QtWidgets
        
        class MyCoolFileDialog(QtWidgets.QWidget):
            ....
        QtWidgets.QFileDialog = MyCoolFileDialog
        

        I am guessing that you might just be using one of the static method of QFileDialog, if that's the case, then just replace the static method rather that the whole class.

        The right term is monkey patching.

        You definitely want to put some warning somewhere about what you are doing here and document it properly.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @SGaist
        So that is what "monkey patching" is? [:shudders:]

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mmiscool
          wrote on last edited by
          #4

          Thanks.
          This was really helpful.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Arsoy
            Banned
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved