Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Showcase
  4. Qt for Python .ui batch compiler shell script

Qt for Python .ui batch compiler shell script

Scheduled Pinned Locked Moved Unsolved Showcase
2 Posts 1 Posters 140 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.
  • pi-squaredP Offline
    pi-squaredP Offline
    pi-squared
    wrote on last edited by pi-squared
    #1

    Please read the updated version down below, as I made a mistake writing this first one. I'm just keeping that mistake here for posterity's sake.

    This is ridiculously simple. All it does is loop through every .ui file (a form created in Qt Creator's Widgets Designer) in its current directory and runs the pyside6-uic command on each of them, which converts them into equivalent Python scripts.

    for file in *.ui; do
        if [ -f "$file" ]; then
            echo "Processing file $file..."
            pyside6-uic "$file" -o "ui_$file.py"
            echo "done!"
        fi
    done
    

    You'll need Python installed of course, and make sure that you have PySide6 (Qt's official Python language bindings) by running pip install pyside6 in the command line. If it isn't already there, the command will install it for you.
    The if [ -f "$file" ]; part checks if the file is actually a file and not a folder.

    1 Reply Last reply
    0
    • pi-squaredP Offline
      pi-squaredP Offline
      pi-squared
      wrote on last edited by
      #2

      UPDATE: I just realised that it outputs a .ui.py file instead of a .py file. Here's the new shell script:

      for file in *.ui; do
          if [ -f "$file" ]; then
              echo "Processing file $file..."
              IFS='.' read -r -a separated <<< "$file"
              pyside6-uic "$file" -o "ui_${separated[0]}.py"
              echo "done!"
          fi
      done
      

      IFS='.' read -r -a separated <<< "$file" is equivalent to separated = file.split('.') in Python.

      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