Actions on selected items from QListWidget when button is clicked
-
Hello everybody,
So, I have a QListWidget with some items (item1, item2, item3,...). In the app I want to make that you can select one item, click a button to confirm and then get some result based on the item you selected.
I know how to get indexes of items like this:int index=ui->mylist->currentRow();
but how to do something when a button(showBtn) is clicked?
-
@YouKnowMe said in Actions on selected items from QListWidget when button is clicked:
Hello everybody,
So, I have a QListWidget with some items (item1, item2, item3,...). In the app I want to make that you can select one item, click a button to confirm and then get some result based on the item you selected.
I know how to get indexes of items like this:int index=ui->mylist->currentRow();
but how to do something when a button(showBtn) is clicked?
You need to create a slot and connect your button's
clicked()
signal to it. -
@YouKnowMe said in Actions on selected items from QListWidget when button is clicked:
@sierdzio I did that, but how to pass an index of the selected item and do actions specific to that item?
const auto &selection = ui->myList->selectionModel()->selectedIndexes(); // Or const auto &selection = ui->myList->selectionModel()->currentIndex();