Rapid Gui Programming – part 2

I just completed the excercise for chapter 7 in which you create a form using Qt Designer and give it the functionality to search and replace some text. As usual I had to port it from PyQt4 to PyQt5. The signals gave me a little problem as they frequently can. In this case it was necessary to declare two custom signals which were used as you can see below. The stumbling block for me was that I didn’t provide for the found signal to pass in integer parameter.

# In porting this from PyQt4 I had to create two signals that
# were created in-line in the original program like this:
#   form.connect(form, SIGNAL("found"), found)
#   form.connect(form, SIGNAL("notfound"), nomore)

# This syntax is no longer possible with PyQt5 and the new style
# signals. The signal must be declared as a class atribute and as
# such must be declared as the first item in the class before any
# method definition. The notfound signal doesn't take an argument so 
# none is given in the declaration. found returns the index of where
# the text was found so it takes an integer argument which must be
# declared like so: found = pyqtSignal(int) vs notfound = pyqtSignal()

                 This is the form that is created

2016-04-08 (3)

Rapid Gui Programming with Python and Qt 1

I spent a lot of time on chapter 6 with the imagechanger.py demo application. I was just trying to follow along but since I had to port it from PyQt4 to PyQt5 it took me some time to get everything working properly. I’ve just now moved on to Chapter 7 which deals with using the Qt Designer an application that allows you to design the UI interactively. This is the preferred way to develop rapidly.