_IlyaVasilev_

Untitled

Oct 21st, 2021
792
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     def load_table(self):
  2.         with open("price.csv", encoding="utf8") as table:
  3.             reader = csv.reader(table, delimiter=';', quotechar='"')
  4.             title = next(reader) + ["Количество"]
  5.             self.table_widget.setColumnCount(len(title))
  6.             self.table_widget.setHorizontalHeaderLabels(title)
  7.             self.table_widget.setRowCount(0)
  8.             for i, row in enumerate(reader):
  9.                 self.table_widget.setRowCount(self.table_widget.rowCount() + 1)
  10.                 for j, elem in enumerate(row):
  11.                     self.table_widget.setItem(i, j, QTableWidgetItem(elem))
  12.  
  13.                 count_item = QTableWidgetItem(str(100 * i))
  14.                 self.table_widget.setItem(i, j + 1, count_item)
  15.         self.table_widget.resizeColumnsToContents()
  16.         self.table_widget.selectionModel().selectionChanged.connect(self.count_changed)
  17.  
  18.     def count_changed(self, selected, deselected):
  19.         if not deselected:
  20.             return
  21.  
  22.         a = deselected.indexes()[0]
  23.         cell_count = self.table_widget.item(a.row(), a.column())
  24.  
  25.         if a.column() != self.table_widget.columnCount() - 1:
  26.             return
  27.  
  28.         cell_price = self.table_widget.item(a.row(), a.column() - 1)
RAW Paste Data