Files From Qt Designer Not Working with PyQt 5.1.1
-
I am new to Python and Qt. I've been using Java and Perl for years but want to be able to use other languages besides Java for a GUI.
I've also got a post on the same question waiting in the queue at python-forum.org, but since it is Qt specific, I started thinking I should post it where the Qt experts are.
I've installed Qt on my system, which is an iMac running OS X 10.8.4. I downloaded and built Qt 5.1.1, then installed Sip and PyQt. Then I wanted to test and be sure PyQt was working and the new Qt install overall, too. I figured it'd be quicker to test in Python than with a C++ example (and I'm having difficulties dealing with Perl - Qt on Perl is on hold).
I found "this page":http://pyqt.sourceforge.net/Docs/PyQt5/designer.html with some basic information on using PyQt. Other pages talk about using pyuic, but this page says it's included and that .ui files from Qt Designer will be parsed automatically by the Qt modules. So I used Qt Designer and tried to create a simple dialog - with just Cancel and Okay buttons and I saved the file, using the names specified on the linked page. Then I renamed ui_imagedialog.ui to ui-imagedialog.py (as specified in the tutorial) and created the program file by cutting and pasting this code in my text editor:
@#!/usr/local/bin/python3
import sys
from PyQt5.QtWidgets import QApplication, QDialog
from ui_imagedialog import Ui_ImageDialogapp = QApplication(sys.argv)
window = QDialog()
ui = Ui_ImageDialog()
ui.setupUi(window)window.show()
sys.exit(app.exec_())@(I added the 1st 2 lines.)
When I first set this up and tried it, I had not renamed ui_imagedialog.ui to ui_imagedialog.py and I got an error on the 5th line ("from ui_imagedialog import..."), which tells me that in Python, if a resource is not there, I get an error at the line where I'm trying to import. Since I didn't get any errors from the 4th line, that makes me think PyQt5 is visible and available (meaning I installed it correctly).
But once I did rename ui_imagedialog.ui to ui_imagedialog.py, I find I get this error:
@Traceback (most recent call last):
File "./QtTest.py", line 5, in <module>
from ui_imagedialog import ImageDialog
File "/Users/hal/Documents/Dev/Puttering/ui_imagedialog.py", line 1
<?xml version="1.0" encoding="UTF-8"?>
^
SyntaxError: invalid syntax@It's having trouble from the very first line in ui_imagedialog.py. According to the information on the page with this example, the .ui file is supposed to be renamed to a .py file (which I've done) and is supposed to be parsed by the uic module that PyQt5 uses. I figure it is being read and treated as a Python file and not being parsed as the page the code is from states.
What am I doing wrong and what do I need to change so the .ui file is parsed as it should be?
-
Okay.
It turns out the wording is ambiguous and you need to use pyuic5 to convert the .ui file to a .py file.
Part of my problem was I could not find pyuic5. It's in /Library/Frameworks/Python.framework/Versions/3.3/bin//pyuic5