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. Ignore the import generated for icon(.qrc) file while converting the .ui file to .py using pyside2-uic

Ignore the import generated for icon(.qrc) file while converting the .ui file to .py using pyside2-uic

Scheduled Pinned Locked Moved Unsolved Qt for Python
pyside2python
6 Posts 4 Posters 1.3k Views
  • 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.
  • P Offline
    P Offline
    PratikTayshete
    wrote on 29 Jul 2023, 16:13 last edited by
    #1

    I have created a .ui file using qt5-designer. Also using the designer I created a .qrc file to store all the icons that I will be using throughout the app. The issue I am facing is that when I convert the .ui file to .py file using the following command pyside2-uic appUI.ui -o appUI.py, I also get an additional import of the icons file which is import icons_rc in the converted .py file.

    Is there an argument that I can use with pyside2-uic that will ignore that import because I want to keep the icons.qrc file in a separate location and import it from there in my main file.

    command.PNG ui_file.PNG

    B S 2 Replies Last reply 29 Jul 2023, 17:48
    0
    • P PratikTayshete
      29 Jul 2023, 16:13

      I have created a .ui file using qt5-designer. Also using the designer I created a .qrc file to store all the icons that I will be using throughout the app. The issue I am facing is that when I convert the .ui file to .py file using the following command pyside2-uic appUI.ui -o appUI.py, I also get an additional import of the icons file which is import icons_rc in the converted .py file.

      Is there an argument that I can use with pyside2-uic that will ignore that import because I want to keep the icons.qrc file in a separate location and import it from there in my main file.

      command.PNG ui_file.PNG

      B Offline
      B Offline
      BamboozledBaboon
      wrote on 29 Jul 2023, 17:48 last edited by
      #2

      @PratikTayshete you can run pyside2-uic --help to get a list of arguments. I don't see anything to ignore rc, but --from-imports might be what you want? It'll use a relative path to the imported file.

      P 1 Reply Last reply 30 Jul 2023, 06:52
      0
      • B BamboozledBaboon
        29 Jul 2023, 17:48

        @PratikTayshete you can run pyside2-uic --help to get a list of arguments. I don't see anything to ignore rc, but --from-imports might be what you want? It'll use a relative path to the imported file.

        P Offline
        P Offline
        PratikTayshete
        wrote on 30 Jul 2023, 06:52 last edited by
        #3

        @BamboozledBaboon I tried using the --from-imports argument but it is still adding an import given below:
        ui_file.PNG
        The structure of my project is this:
        project_structure.PNG
        And I am trying to import the icons.py file in my app.py file as given below:
        main_file.PNG
        When the execute the app.py file, it gives me this error:
        error_message.PNG

        J B 2 Replies Last reply 30 Jul 2023, 07:31
        0
        • P PratikTayshete
          30 Jul 2023, 06:52

          @BamboozledBaboon I tried using the --from-imports argument but it is still adding an import given below:
          ui_file.PNG
          The structure of my project is this:
          project_structure.PNG
          And I am trying to import the icons.py file in my app.py file as given below:
          main_file.PNG
          When the execute the app.py file, it gives me this error:
          error_message.PNG

          J Offline
          J Offline
          JonB
          wrote on 30 Jul 2023, 07:31 last edited by JonB
          #4

          @PratikTayshete
          I don't have pyside2-uic, but I don't see that --from-imports does anything other than alter import ... to from . import ....

          There isn't a way to suppress importing icons_rc. But pyside2-uic is just some Python script itself, so easy to change. I look in https://github.com/pyside/pyside2-tools/blob/dev/pyside2-uic to see its source. The import-writing function, def write_import(), is at https://github.com/pyside/pyside2-tools/blob/f68388cf547c0d63a5d4a145f65aa9fa90529d52/pyside2uic/Compiler/misc.py#L27 (called from https://github.com/pyside/pyside2-tools/blob/f68388cf547c0d63a5d4a145f65aa9fa90529d52/pyside2uic/Compiler/compiler.py#L99). I'm sure you could tweak that to exclude your icons_rc if required.

          Or, write a couple of lines script file to edit the .py file in-place to remove that line.

          1 Reply Last reply
          0
          • P PratikTayshete
            29 Jul 2023, 16:13

            I have created a .ui file using qt5-designer. Also using the designer I created a .qrc file to store all the icons that I will be using throughout the app. The issue I am facing is that when I convert the .ui file to .py file using the following command pyside2-uic appUI.ui -o appUI.py, I also get an additional import of the icons file which is import icons_rc in the converted .py file.

            Is there an argument that I can use with pyside2-uic that will ignore that import because I want to keep the icons.qrc file in a separate location and import it from there in my main file.

            command.PNG ui_file.PNG

            S Offline
            S Offline
            StarterKit
            wrote on 30 Jul 2023, 12:15 last edited by StarterKit
            #5

            Hi @PratikTayshete
            I'm with uic from PySide6 currently but some time ago my project was on PySide2 and it had a lot of ui-files at that time translated to python with pyside2-uic.
            What looks strange for me - this line import icons_rc, how it appears in you py-file.
            I.e. what pyside2-uic does - it translates one file format (ui) into another (py). And in my case there was no such line. It brings a thought into my head that your initial ui-file is somehow linked with qrc-resource file that your use. Is it true?
            I.e. I see 2 options here:

            1. your don't need resources in your ui-file but by some reason it contains it. Then you should clean your source ui-file (To be on a safe side you may create a brand new ui-file with a couple of simple widgets and pass it to uic in order to see if this line appear in output or not)
            2. you use resources in your ui-file, for example to have some icons in some places. In this case I belive it is some architectural restriction about how Qt expects your project should be sturctured. In this case probably more brainstrorming is needed about what you actually want to achieve.
            1 Reply Last reply
            0
            • P PratikTayshete
              30 Jul 2023, 06:52

              @BamboozledBaboon I tried using the --from-imports argument but it is still adding an import given below:
              ui_file.PNG
              The structure of my project is this:
              project_structure.PNG
              And I am trying to import the icons.py file in my app.py file as given below:
              main_file.PNG
              When the execute the app.py file, it gives me this error:
              error_message.PNG

              B Offline
              B Offline
              BamboozledBaboon
              wrote on 30 Jul 2023, 19:46 last edited by BamboozledBaboon
              #6

              @PratikTayshete
              I'm too new to this to suggest a proper solution... but this seems to work for my for pyside6 to correctly import the _rc.py file

              pyside6-uic appUI.ui -o appUI.py --absolute-imports --python-paths ./icons/
              

              Note: When I run pyside6-uic --help I see the following

              --rc-prefix                     Python: Generate "rc_file" instead of
                                                "file_rc" import
              

              This suggest to me that you are expected to name of your compiled resource python files to either prefix or suffix with rc_ or _rc respectively.

              e5ba5886-00aa-4dac-b61c-9bf28770a84c-image.png

              1 Reply Last reply
              0

              4/6

              30 Jul 2023, 07:31

              • Login

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