How do I get the entire row value selected for the table value in pyqt5?

Asked 2 years ago, Updated 2 years ago, 78 views

I want to select the values shown in the table and put them in another table, but I don't know how to find the selected total table row values I've searched, but QItemSelectionModel is tracking the selected items in this view 도움이ㅜ Is there any information that can help?

pyqt5 python pyqt

2022-09-22 18:33

1 Answers

Pyqt is actually an area where qt knowledge is needed more than Python knowledge.

It can be easier if you have knowledge of Windows programming.

First of all, the table on the qt side has item base and model base.

QTableWidget, for example, a row is made up of several cells.

The code below is an example of creating one row.

self.tw2 = self.ui.tableWidget_2
self.tw2.setRowCount(1)
self.tw2.setItem(0, 0, QtWidgets.QTableWidgetItem("Yhjung"))
self.tw2.setItem(0, 1, QtWidgets.QTableWidgetItem("Korea"))
self.tw2.setItem(0, 2, QtWidgets.QTableWidgetItem("10"))

The example below is to copy row assuming that you have two QTableWidgets. tw1 is another QTableWidget.

@pyqtSlot(QtCore.QModelIndex)
def slot2(self, modelIndex):
    row = modelIndex.row()
    row_count = self.tw1.rowCount()
    self.tw1.insertRow(row_count)
    self.tw1.setItem(row_count, 0, QtWidgets.QTableWidgetItem(self.tw2.item(row, 0).text()))
    self.tw1.setItem(row_count, 1, QtWidgets.QTableWidgetItem(self.tw2.item(row, 1).text()))
    self.tw1.setItem(row_count, 2, QtWidgets.QTableWidgetItem(self.tw2.item(row, 2).text()))


2022-09-22 18:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.