Pages

Connecting widget

In the paragraph Shape-Changing Dialogs, in chapter 2 of their book, Jasmin and Mark provide us an example a bit complicated and too boring to be reported here how to create a dialog that change its own size.

It's that kind of dialogs that have a mandatory part and an optional one. Usually only the first part is shown but, if we gently ask, we can have a look also at the second one.

The example is about a dialog for inputting the parameter for sorting our data. Only a primary key is mandatory, but we can set also a secondary and even a tertiary key.

The most interesting part of the example is where we connect widgets in the dialog. It's quite immediate to do that in Qt Designer. It's enough to click on the F4 key and we are ready to estabilish connections.

In past examples we have programmatically created the connection between the OK/Cancel buttons to the dialog accept() / dialog() slots. Actually we can do that also visually.

We click on a button an drag the generated line to the dialog background. When we leave it, the Designer knows we want to create a connection from the button to the dialog, now it needs to know from which signal to which slot. That what it asks us.

In this case we connect the clicked() slot from the button to the accept() or reject() slot of the dialog.

In a similar way we can do to make disappear a widget. We simply connect a checkable button (I mean, a button with the checkable property set) to the widget, and specify that the signal/slot relation is done by the button toggle() and widget setVisible().

I wrote this post as homework while reading "C++ GUI Programming with Qt 4, Second Edition" by Jasmin Blanchette and Mark Summerfield.

No comments:

Post a Comment