Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Design Tooling
  3. Qt Design Studio
  4. accessing several .ui files in python
Forum Updated to NodeBB v4.3 + New Features

accessing several .ui files in python

Scheduled Pinned Locked Moved Unsolved Qt Design Studio
11 Posts 4 Posters 1.4k 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.
  • E explorer100
    23 Jul 2024, 07:23

    My objective is to have a main menu and several custom dialogs created in qt designer. Then through the main menu be able to invoke the custom dialogs in one python application. Is there a best practice for doing this? I would appreciate a simple python example. I was not able to have the main menu and the custom dialogs in one .ui file while loading both .ui files in the python program crashes the app.

    J Online
    J Online
    JonB
    wrote on 23 Jul 2024, 07:36 last edited by
    #2

    @explorer100
    You can have as many separate .ui files as you want/need. Show your code which "crashes" on loading these.

    E 1 Reply Last reply 23 Jul 2024, 07:46
    0
    • J JonB
      23 Jul 2024, 07:36

      @explorer100
      You can have as many separate .ui files as you want/need. Show your code which "crashes" on loading these.

      E Offline
      E Offline
      explorer100
      wrote on 23 Jul 2024, 07:46 last edited by
      #3

      @JonB thank you Jon. I'm very new to qt designer... so first is it a good practice to have .ui files for each custom dialog then load each in the python app? or is it better (if at all possible) to have everything defined in one .ui file then load everything once?

      J 1 Reply Last reply 23 Jul 2024, 07:56
      0
      • J Online
        J Online
        JonB
        wrote on 23 Jul 2024, 07:48 last edited by
        #4

        One .ui file can only design one page/window/dialog. Your dialogs will be shown separately from one another so you will want separate .uis for these.

        1 Reply Last reply
        1
        • E explorer100
          23 Jul 2024, 07:46

          @JonB thank you Jon. I'm very new to qt designer... so first is it a good practice to have .ui files for each custom dialog then load each in the python app? or is it better (if at all possible) to have everything defined in one .ui file then load everything once?

          J Online
          J Online
          JonB
          wrote on 23 Jul 2024, 07:56 last edited by JonB
          #5

          @explorer100
          On a separate note, especially since you are beginner. I would not take the approach of "loading" .ui files at runtime. Read through Using .ui files from Designer or QtCreator with QUiLoader and pyside6-uic. You sound like you are doing Option B: Loading it directly. If you do this you will not be able to access all your widgets so easily. I would always recommend the alternative, Option A: Generating a Python class. It's a touch more work --- you have to run a pyside6-uic tool step to produce Python code from the .ui in a generated .py file (I think Creator can run this for you each time) --- but in return you get proper coding-time support for all your widgets.

          P 1 Reply Last reply 25 Jul 2024, 01:07
          2
          • E Offline
            E Offline
            explorer100
            wrote on 23 Jul 2024, 08:03 last edited by explorer100
            #6

            OK.. thank you very much Jon... will use this approach!

            1 Reply Last reply
            0
            • E Offline
              E Offline
              explorer100
              wrote on 23 Jul 2024, 10:39 last edited by
              #7

              Hello. Any recommended approach of communication between the main window and the custom dialogs?

              J 1 Reply Last reply 23 Jul 2024, 11:57
              0
              • E explorer100
                23 Jul 2024, 10:39

                Hello. Any recommended approach of communication between the main window and the custom dialogs?

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 23 Jul 2024, 11:57 last edited by
                #8

                @explorer100 said in accessing several .ui files in python:

                Any recommended approach of communication between the main window and the custom dialogs?

                As always in Qt: signals/slots

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • J Online
                  J Online
                  JonB
                  wrote on 23 Jul 2024, 12:00 last edited by JonB
                  #9

                  There are two basic possibilities:

                  • Expose "getter/setter" methods from the dialog which the outside world (main window) can call, for the dialog to set values in the widgets and return values after user interaction. This is usually the simplest approach, e.g. if all you do is exec() the dialog as modal.
                  • For more advanced information exchange you could use signals/slots (in either/both directions). Depends what your custom dialogs do.
                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    explorer100
                    wrote on 23 Jul 2024, 16:24 last edited by explorer100
                    #10
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • J JonB
                      23 Jul 2024, 07:56

                      @explorer100
                      On a separate note, especially since you are beginner. I would not take the approach of "loading" .ui files at runtime. Read through Using .ui files from Designer or QtCreator with QUiLoader and pyside6-uic. You sound like you are doing Option B: Loading it directly. If you do this you will not be able to access all your widgets so easily. I would always recommend the alternative, Option A: Generating a Python class. It's a touch more work --- you have to run a pyside6-uic tool step to produce Python code from the .ui in a generated .py file (I think Creator can run this for you each time) --- but in return you get proper coding-time support for all your widgets.

                      P Online
                      P Online
                      Pl45m4
                      wrote on 25 Jul 2024, 01:07 last edited by Pl45m4
                      #11

                      @JonB said in accessing several .ui files in python:

                      You sound like you are doing Option B: Loading it directly. If you do this you will not be able to access all your widgets so easily. I would always recommend the alternative, Option A: Generating a Python class. It's a touch more work --- you have to run a pyside6-uic tool step to produce Python code from the .ui in a generated .py file (I think Creator can run this for you each time) --- but in return you get proper coding-time support for all your widgets.

                      An interesting thing I've noticed lately:
                      We had a similar topic in the German section where OP used the QUiLoader/"direct" approach, but then struggled with (as you also mentioned) accessing and connecting the child- and sub-Widgets from the UI-based QWidget constructed by QUiLoader.
                      I've also recommended using the uic tool to convert the .ui to a .py class, esp. when you are a beginner.

                      However, I was told that at some other place (Python forum) OP read about "the Python community" condemning this "generator" approach, since it violates some principles of interpreted languages... :D

                      Yeah, sure... :D
                      I'm not a Python-hater, or a Python-fanboy, but without already popular frameworks providing Python-bindings, nobody would use Python in these cases... the whole community profits. So you might have to accept it's downsides, which come with the fact that these frameworks weren't intented for Python-like languages and are only usable through bindings.

                      Try to write your own platform independent, holistic GUI framework like Qt from scratch using Python only... Good luck with that ;-)


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      1 Reply Last reply
                      0

                      11/11

                      25 Jul 2024, 01:07

                      • Login

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