CommandLink buttons with Qt

Windows Vista introduced the concept of command links. A command link is a special button type primarily designed to streamline Wizard-like interfaces. Pressing a command link should always take you to a different page, just like in a web browser. In addition to the visual difference, it can also include a descriptive text.

Example :
Qt command link

A command link class did not make it into 4.3, and it has not yet been decided if it will be part of our standard widget set.
However some support was added in the style API to support these features, so I decided to make a small
example on how to implement this functionality using Qt 4.3. In fact, the screen shot above was made using Qt.

You can try out the following subclass of QPushButton that adds these features : commandlink.h and commandlink.cpp . Note that the size hint calculation is somewhat rudimentary and does not guarantee the visibility of the description text.

To use this in a QWizard you could do something like this :

QWizard wizard;
QWizardPage page;
QVBoxLayout layout;
CommandLink button;
button.setText("&Press me!");
button.setDescription("Pressing this button should do something");

The only thing remaining now is to connect the clicked signal to for instance QWizard::next(). Note that the code will also work on other platforms and styles. This is the above button rendered with Plastique style :

Qt command link

Update 05.21.07 : Tweaked the font settings a bit

Blog Topics: