How to move items between two QListWidgets?

269 Views Asked by At

I want to create a pyqt5 GUI in which the user should pick the wanted variables on the left and they should show up on the right hand side. This is what the GUI looks like:

enter image description here

Basically, I want to click the variables on the left listWidget, and they should show up in the list widget on the right (chosenitem_list), and then ideally dissapear from the left listWidget. Otherwise, I could add a button once all the desired variables have been selected which transfers them to the other side. I am trying to do this using the item_clicked method in my code below, but when I click on them nothing happens so I am stuck. What am I doing wrong?

class MainWindow(QMainWindow):

    def __init__(self):
        super(MainWindow, self).__init__()
        loadUi('browse.ui',self)
        self.listWidget.clicked.connect(self.item_clicked)

    def item_clicked(self):
        item = QtWidgets.QListWidgetItem() 
        item = self.listWidget.currentItem()
        self.chosenitem_list.addItem(item)
1

There are 1 best solutions below

0
eyllanesc On

You have to clone the QListWidgetItem:

def item_clicked(self, index):
    item = self.listWidget.itemFromIndex(index)
    it = item.clone()
    self.chosenitem_list.addItem(it)