Qt5.9 control listWidget usage (QListWidget basic usage)

This blog mainly summarizes the basic usage of the listWidget control, which explains two methods to add content to the listWidget control, namely the UI interface operation method and the writing code addition method. These two methods will be explained in detail below.

 

Explanation of commonly used functions:

(1) addItem function
void addItem (const QString & label)
void addItem (QListWidgetItem * item)
void addItems (const QStringList & labels) to
add one or more items.

(2)insertItem函数
void insertItem ( int row, QListWidgetItem * item )
void insertItem ( int row, const QString & label )
void insertItems ( int row, const QStringList & labels )

Insert a new item into the list box.

(3) count () function
int count () const

The total number of list items including hidden list items.

(4)currentRow函数
int currentRow () const

Returns the serial number of the currently selected item.

(5) takeItem 函数
QListWidgetItem * takeItem (int row)

Delete the item in row row.

 

1.1 Create a new widget project and drag the listWidget control into the interface, as shown below:

 

 

1.2 There are two ways to add content to the list item.

1.2.1 UI interface operation method:

First, double-click the listWidget control, and after the following interface pops up, operate according to the following figure, and get the display result as shown in the figure below:

 

 

 

1.2.2 Writing code addition method

In the widget constructor, add the following code:

 

Double-click the listWidget button and add the following code in the button slot function:

 

1.2.3 The structure runs enough, and the result is shown in the following figure:

 

1.2.4 Click the listWidget button to output the following content:

 

 

 

Reference content:

http://blog.csdn.net/xgbing/article/details/7768226

http://blog.csdn.net/gdutlyp/article/details/50370536

Guess you like

Origin blog.csdn.net/jiesunliu3215/article/details/108843337