Friday, September 24, 2010

Qt Designer bad knowhows (*)

"bad knowhow" is a Japangrish meaning it is something you have to use knowing it is not a nice way.

Qt designer is a good tool but there are several things you need to know until you get familiar with it.

1) Making widgets expand within a window
It is the first thing most people takes a few hours googling to get the answer. The answer is tricky.

- Drag and drop arbitrary widget (button or spacer is enough)
- Right click the background of the window (not the widget you have dropped)
- Select Layout - Layout Horizontally (or Layout Vertically) in the pop-up menu

You cannot select Layout- Layout Horizontally (Vertically) until you create a widget on the window.

2) Moving a layout from its parent to another.
When the UI gets complicated, it is often difficult to move the right layout to the right place.

To move the right layout:
- Select the layout in the Object Inspector.
- Click the layout
Qt Designer will pick the selected layout.

To the right place:
- When clicking the layout, click near the top left corner of the layout
- Drag and drop it to the new parent in the Object Inspector
Unless you click new the top left corner, you'll be puzzled when dragging it to the Object Inspector

3) Try to copy and paste a widget and get error "Cannot paste widgets. Designer could not find a container without a layout to paste into."

My solution is to create a new dummy window (with ctrl-N) and copy&paste to it. then drag and drop it to wherever you wish to. There may be other ways.

I will add a screen shot on request.
When using the qt-designer generated file (*.ui), never modify automatically generated file. For example, I use Python and I convert *.ui to *.py with pyuic4 tool. I never modify the .py file by hand, which would halve the qt designer's strength. You will quite often want to update the GUI design and once you have modified the generated file, your modification to the source code would be lost. Insted, use the file from another. Same applies to C++ users to.

By the way qt designer is in qt-devel yum package (e.g. qt-devel-4.6.3-8.fc13.i686). It tool a while for me to find it.

No comments: