In the former Fractal Generator related post I wrote that I had to modify the generated ui_main.h header file in order to change the QLabel widget to a custom widget called ArthurCanvas. Modifying the generated file has an obvious drawback. When I develop the GUI further with Designer and re-generate the header file, I have to make the changes every time.
Meanwhile I learn QT and develop Arthur I started to read “The Book of Qt 4: The Art of Building Qt Applications”. In this book I have found there is a simple way to use custom widgets in place of some QT widgets in Designer. In our case we derived ArthurCanvas from QLabel. All what I had to do is to open the ui file in Designer. Right click the QLabel in my main window and select Promoted widgets from the context menu. Then I specified ArthurCanvas as the class and arthur_canvas.h as the header file. When I was done I right clicked the QLabel widget again and in the context menu I could choose promote to ArthurCanvas. That is it. I saved the ui. Then I called qmake to regenerate the makefile. I’m not sure whether that was necessary. Probably not. Then I cleaned the environment with make clean. Finally I called make. The header file was regenerated and the binary executable was built. Now, I have ArthurCanvas in the header file instead of QLabel. Everything else is as before. The executable behaves the same way.
You can download the sources from here: fractal004