Hi there
PyQt is not available as tag, but this should be a simple question anyway:

  • drag & drop: from QListWidget to QListwidget
  • pushButton action: inserts chosen items from second QListWidget into QTableWidget
    But: when i run my code - most of the time the chosen items are inserted twice into my QTableWidget,
    sometimes the code runs like expected - and i can't figure out why.
    Of course i tried a "print(num)", and the added really occurs twice, for example:
    (0) ListEdit
    (0) ListEdit
    (1) TextEdit
    (1) TextEdit
    ... a.s.o.

Here's the snippet:

    vheader = self.tableWidget.verticalHeader()
    r_count = self.tableWidget.rowCount()
    c_count = self.tableWidget.columnCount()
    for num in range(self.listWidget_3.count()):
            name = self.listWidget_3.item(num).text()
            if name == 'LineEdit':
                this = r_count
                that = (c_count -1)
                line_comboBox = QComboBox()
                new_line = QLineEdit()
                self.tableWidget.setCellWidget(this, that -1, line_comboBox)
                self.tableWidget.setCellWidget(this, that, new_line)
                vheader.setSectionResizeMode(this, QHeaderView.ResizeToContents)
            elif ......:

Err.. working on PyCharm. PyQt 5.13, Python 3.7.4 - if you'd need any further information: let me know.

..my bad - i'm sorry. In this part there's no mistake, but other "name"s had, compared to this 'line 11.' a


what of course doesn't work.
Thanks for your efforts.

Since "occurs twice" appears to be the cause and what you need to investigate, where is the code that sets up or handles the drag, drop and mouse events?

PS. The code supplied doesn't appear to be causing this.

commented: Thank you! +0

Thank you, already solved - my bad: made a second rowcount on the other items.. events? ..in another class?! (..they will be, cause this's just been a quick workaround)