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. QDialog override reject when loading .ui file
Qt 6.11 is out! See what's new in the release blog

QDialog override reject when loading .ui file

Scheduled Pinned Locked Moved Solved Qt for Python
4 Posts 3 Posters 524 Views 1 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.
  • T Offline
    T Offline
    tilz0R
    wrote on last edited by
    #1

    I have a custom dialog that is based on QDialog class. I load .ui file to python.

    
    # Main window class
    class MyDialog(QDialog):
        def __init__(self):
            super().__init__()
            self.load_ui()
            self.ui.show()
    
        # Load UI from file
        def load_ui(self):
            loader = QUiLoader()
            path = os.fspath(Path(__file__).resolve().parent / 'ui' / 'dialog.ui')
            ui_file = QFile(path)
            ui_file.open(QFile.ReadOnly)
            self.ui = loader.load(ui_file, parentWidget = self)
            ui_file.close()
    
        # Override reject
        def reject(self):
            print("reject")
    

    I call it with self.testwidget = MyDialog() and it opens well. But reject method is not part of the UI. How can I add reject method if UI is loaded from .ui file? I want to do something on reject callback.

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

      Hi,

      The recommended way to use designer based widget is to generate the Python code from your ui file.

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

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tilz0R
        wrote on last edited by
        #3

        Thanks - is there a way to create ui_xxx.py file directly when you save .ui file in QtCreator ?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          friedemannkleint
          wrote on last edited by
          #4

          See https://doc.qt.io/qtforpython-6/tutorials/basictutorial/uifiles.html

          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