Skip to content


Qt Jambi – ListView with checkbox

Was looking for a way to add check boxes to ListViews on Qt Jambi, and a lot of the solutions came up way too complicated than what needs to be.

The following code would add an item with a checkbox to a ListViewWidget (Not a model based listview)

QListWidgetItem item = new QListWidgetItem("test1");
item.setFlags(ItemFlag.ItemIsUserCheckable, ItemFlag.ItemIsEnabled);
item.setCheckState(CheckState.Checked);
list.addItem(item);

 

To read from the list, a quick way is

int count = list.count();

for (int i=; i<count; i++) {
list.item(i).checkState() == CheckState.Checked

}

Posted in Java, Qt. Tagged with , , , , .