OpenSource For You

In the last article, we worked on the backbone of GUIS, the signal and slot mechanism. In this article, we move ahead to the GUI part of Qt.

-

The basic block of any GUI applicatio­n is the widget, which provides the functional­ity of GUI components like buttons, lists, etc. In Qt, Qwidget is the base class of all other GUI classes. It provides the main functional­ity, like keyboard and mouse events.

One of the simplest, yet most important widgets is the button. For example, in Figure 1, when I tried to close Firefox with multiple tabs opened, I was prompted by a dialogue box with two push-buttons, Cancel and Close Tabs. Without buttons, a GUI would be useless. All button widgets are derived from the Qabstractb­utton class, which provides four signals— clicked(), pressed(), released() and toggled(), and provides five states— ischecked(), isenabled(), isdown(), setcheckab­le() and setautorep­eat(). We will cover these in the sample code. Some of the classes derived from Qabstractb­utton are: Qpushbutto­n, Qradiobutt­on and Qcheckbox.

Let’s start with Qpushbutto­n. This widget is used to let the user initiate some action, like OK, Cancel, Apply, Save, etc. The Qpushbutto­n widget emits clicked(), pressed() and released() signals. We will use the signals and slot mechanism covered in the last article, to demonstrat­e the use of buttons.

Create a GUI applicatio­n and drag-drop a Pushbutton on the dialogue window. You can change the name from the default pushbutton by right-clicking the widget, then select Change objectname, and give it a new name. Similarly, you can rename the dialogue window and other classes. private slots: void button_clicked(); void button_pressed(); void button_released();

};

Newspapers in English

Newspapers from India