INF1511 - Chapter 8 - Using Basic Widgets
INF1511 - Chapter 8 - Using Basic Widgets
Radio buttons are used to allow a user to select only one option from two or more options.
setText() - used to set the text of the radio button. To specify a shortcut key for the
radio button, precede the preferred character in the text with an ampersand (&).
setChecked() - pass the Boolean value true to this method to make the radio button
the default.
Radio buttons emit the following signals;
toggled() - emitted whenever button changes its state from checked to unchecked or
vice versa.
clicked() - emitted when a button is activated (i.e., pressed and released) or when
its shortcut key is pressed.
stateChanged() - emitted when a radio button changes its state from checked to
unchecked or vice versa.
2. Using Checkboxes
Check boxes allow the selection of more than one option.
setTristate() - pass Boolean value true to this method to use the “no change” state
of the checkbox. With this state, you give the user the option of neither checking nor
unchecking a checkbox.
setIcon() - used to display an icon with the checkbox.
setText() - used to set the text of the checkbox. To specify a shortcut key for the
checkbox, precede the preferred character with an ampersand in the text.
setChecked() - pass Boolean value true to this method to make the checkbox
checked by default.
clicked() - the signal is emitted when a checkbox is activated (i.e. pressed and
released) or when its shortcut key is typed.
stateChanged() - the signal is emitted whenever a checkbox changes its state from
checked to unchecked or vice versa.
3. ScrollBars
Scrollbars are used for viewing documents or images that are larger than the view area.
There are two types of scrollbars, HorizontalScrollBar and VerticalScrollBar.
Slider handle: Used to move to any part of the document or image quickly.
Scroll arrows: arrows on either side of the scrollbars that are used to accurately navigate to a
particular place in a document or image.
Page control: The page control is the background of the scrollbar over which the slider
handle is dragged.
value() - retrieves a value that indicates the distance of the slider handle from the
start of the scrollbar.
setValue() - sets the value of the scrollbar and hence the location of the slider handle
in the scrollbar.
sliderPressed() - emitted when the user starts to drag the slider handle.
4. Sliders
Sliders are used to represent some integer value.
There are two types of Sliders, HorizontalSlider and VerticalSlider.
sliderPressed() - emitted when the user starts to drag the slider handle.
The List widget is used to list items, the items can then be viewed, added to and removed
from the list.
insertItem() - inserts a new item with the specified text into the List widget at the
specified row.
insertItems() - inserts multiple items from a list of supplied labels, starting at the
specified row.
takeItem() - removes and returns item from the specified row in the List widget.
setCurrentItem() - replaces the current item in the list with the specified item.
addItem() - inserts an item with the specified text at the end of the List widget.
addItems() - inserts items with the specified text at the end of the List widget.
currentRow() - returns the row number of the current item. If there is no current
item, it returns the value -1.
setCurrentRow() - selects the specified row in the List widget.