Although you can add items to the List Widget
item manually through Property Editor
, sometimes you need to add items to the List Widget
item dynamically through code. Let's create an application that explains the process of adding items to List Widget
.
In this application, you will use Label
, Line Edit
, Push Button
, and List Widget
. The List Widget
item will be empty initially, and the user is asked to enter desired food items into Line Edit
and select an Add to List
button. The entered food item will then be added to the List Widget
item. All subsequent food items will be added below the previous entry.
Perform the following steps to know how items can be added to the List Widget
item:
- We will begin by creating a new application based on the
Dialog without Buttons
template and dragging and droppingLabel
,Line Edit
,Push Button
, andList Widget
onto the form. - Set the
text
property of theLabel
andPush Button
widgets toYour favourite food item
and...