Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Designer for PyQt on OSX 10.6

I liked Qt Designer on Windows so much for making GUIs for Python applications (using PyQt4) that I went and tried to install it on my Mac (under OSX 10.6.6).

At this point, I have successfully installed SIP, Qt4, and PyQt4.

The PyQt binary installers (for Windows) include a version of Qt Designer that works with PyQt. On OSX, there is no binary installer, just source. So no Qt Designer.

The Qt website offers Qt Creator as a download, but as far as I can tell, it requires that you're writing code in C/C++.

Is there a way to make Qt Creator work with PyQt? Or is there another GUI designer for PyQt that works on a Mac?

Thanks! -Wesley

like image 544
Wesley Avatar asked Feb 18 '11 17:02

Wesley


People also ask

Can I use Qt Designer on Mac?

Install Qt Designer on Windows or Mac. Tiny download: Only 40MB!

Is Qt Designer part of pyqt5?

Installing and Running Qt Designer Here, you create a Python virtual environment, activate it, and install pyqt5 and pyqt5-tools . pyqt5 installs PyQt and a copy of the required Qt libraries, while pyqt5-tools installs a set of Qt tools that includes Qt Designer.

How do I download pyqt5 on Mac?

Install PyQt5 on macOS You can download macOS installers for Python 3 from the Python homepage. Once installed, you should be able to use the pip3 install command above to install PyQt5. Another alternative is to use Homebrew. Homebrew is a package manager for command-line software on macOS.


1 Answers

If you've installed Qt4, then you have Qt Designer. If you used the installer from qt.nokia.com, it should be in /Developer/Applications/Qt.

Qt Designer itself works just fine with PyQt. Qt designer just spits out XML describing the UI structure. If you were using standard Qt with C++, you would have to run the uic tool to generate C++ from the .ui files. Likewise, with PyQt4, you must run pyuic4 on the generated .ui file to create python source from it.

If you're looking for a full IDE solution that handles all of this with PyQt automatically, I'm unaware of the existence of one. I just have a build_helper.py script that processes all of my .ui files and places them in the appropriate place in the python package I'm developing. I run the build helper script before running the actual main program to ensure that the generated code is up to date.

All of my .ui files go into a subfolder ui in the project root. The script then creates python source and places it into 'myapp/ui/generated'.

For example:

import os.path
from PyQt4 import uic

generated_ui_output = 'myapp/ui/generated'

def process_ui_files():
    ui_files = (glob.glob('ui/*.ui'),
                glob.glob('ui/Dialogs/*.ui'),
                glob.glob('ui/Widgets/*.ui')))
    for f in ui_files:
        out_filename = (
            os.path.join(
                generated_ui_output,
                os.path.splitext(
                    os.path.basename(f))[0].replace(' ', '')+'.py')
        )
        out_file = open(out_filename, 'w')
        uic.compileUi(f, out_file)
        out_file.close()

if __name__ == '__main__':
    process_ui_files()

I also have a few other functions in there for running pyrcc4 for resource compilation and pylupdate4 and lrelease to generate translations.

like image 73
Grant Limberg Avatar answered Sep 19 '22 15:09

Grant Limberg