def particulasTabla(self, particulas): labels = ['Id', 'origen', 'destino', 'velocidad', 'color', 'distancia'] self.ui.tblParticulas.clear() self.ui.tblParticulas.setColumnCount(6) self.ui.tblParticulas.setRowCount(len(particulas)) self.ui.tblParticulas.setHorizontalHeaderLabels(labels) row = 0 for particula in particulas: idx = QTableWidgetItem(str(particula.id)) origen = QTableWidgetItem('(' + str(particula.origen.x) + ',' + str(particula.origen.y) + ')') destino = QTableWidgetItem('(' + str(particula.destino.x) + ',' + str(particula.destino.y) + ')') velocidad = QTableWidgetItem(str(particula.velocidad)) color = QTableWidgetItem("") color.setBackground( QBrush( QColor.fromRgb(particula.color.r, particula.color.g, particula.color.b))) distancia = QTableWidgetItem(str(particula.distancia)) self.ui.tblParticulas.setItem(row, 0, idx) self.ui.tblParticulas.setItem(row, 1, origen) self.ui.tblParticulas.setItem(row, 2, destino) self.ui.tblParticulas.setItem(row, 3, velocidad) self.ui.tblParticulas.setItem(row, 4, color) self.ui.tblParticulas.setItem(row, 5, distancia) row += 1 self.ui.tblParticulas.horizontalHeader().setSectionResizeMode( QHeaderView.ResizeToContents)
def get_uneditable_table_widget_item(in_object, is_inf=False): """ :param in_object: String to display :param is_inf: if infection_state is True, cell will be red :return: QTableWidgetItem that can be used in compartment_table or variable_table """ out_item = QTableWidgetItem(str(in_object)) out_item.setFlags(Qt.ItemIsEnabled) if is_inf: out_item.setBackground(QBrush(Qt.red)) return out_item
def createRow(self, pos, key, val, pin): newKeyItem = QTableWidgetItem() newKeyItem.setText(key) newValItem = QTableWidgetItem() newValItem.setText(val) color = PySide2.QtGui.QColor(200, 220, 200) if bool(pin): # newKeyItem.setIcon(QIcon.fromTheme('emblem-important')); newKeyItem.setIcon(IconFactory.getIcon('push_pin')) newKeyItem.setBackground(color) newValItem.setBackground(color) self.insertRow(pos) self.setItem(pos, 0, newKeyItem) self.setItem(pos, 1, newValItem)
def on_table_itemDoubleClicked(self, item): self.is_double_clicked = True # print('双击') # 判断双击的是温度还是湿度 if self.table.currentColumn() == 1: # 获取当前的实际温度 one = float(self.table.currentItem().text()) # 需要修改成的温度 if abs(self.one_low - one) < abs(self.one_high - one): high = random.uniform(self.one_low, self.one_low + 1) else: high = random.uniform(self.one_high - 1, self.one_high) # 设置单元格内容 self.table.currentItem().setText(str(high)) # 获取选中单元格的行号 ROW = self.table.currentRow() # 获取此行的第0列内容 logs_time = self.table.item(ROW, 0).text() tb = 'LOGS_' + self.sel_name self.conn.up_data(tb, high, logs_time, 'one') # 设置单元格内容及颜色 newitem = QTableWidgetItem(str(high)) newitem.setBackground(self.bgbruse) self.table.setItem(ROW, 1, newitem) # 把数字转换成字符串 elif self.table.currentColumn() == 2: # 获取当前的实际湿度 two = float(self.table.currentItem().text()) # 需要修改成的湿度 if abs(self.two_low - two) < abs(self.two_high - two): high = random.uniform(self.two_low, self.two_low + 1) else: high = random.uniform(self.two_high - 1, self.two_high) # 设置单元格内容 self.table.currentItem().setText(str(high)) # 获取选中单元格的行号 ROW = self.table.currentRow() # 根据行号获取时间 logs_time = self.table.item(ROW, 0).text() tb = 'LOGS_' + self.sel_name self.conn.up_data(tb, high, logs_time, 'two') # 设置单元格内容及颜色 newitem = QTableWidgetItem(str(high)) newitem.setBackground(self.bgbruse) self.table.setItem(ROW, 2, newitem) # 把数字转换成字符串
def draw_graphical_genotype_map(): count = 0 orig_alleles_dict = dict() GraphicalGenotypeController.ui.genotypingTable.setShowGrid(False) GraphicalGenotypeController.ui.genotypingTable.horizontalHeader().hide( ) GraphicalGenotypeController.ui.genotypingTable.verticalHeader().hide() from controllers.MarkersTabController import MarkersTabController gen_length = max([ len(marker.alleles[0]) if len(marker.alleles) != 0 else 0 for marker in MarkersTabController.markers ]) for i in range(gen_length): GraphicalGenotypeController.ui.genotypingTable.insertColumn(i) GraphicalGenotypeController.ui.genotypingTable.setColumnWidth( i, 10) # GraphicalGenotypeController.ui.genotypingTable.resizeColumnToContents(i) for row, marker in enumerate(MarkersTabController.markers): GraphicalGenotypeController.ui.genotypingTable.insertRow(row) alleles = marker.alleles[0] if len( marker.alleles) != 0 else 'No Data' orig_alleles_dict[row] = [marker.id, alleles, marker.name] if alleles == 'No Data': pass # for col_index in range(gen_length): # item = QTableWidgetItem() # item.setBackground(GraphicalGenotypeController.colors[alleles]) # item.setFlags(QtCore.Qt.ItemIsEnabled) # GraphicalGenotypeController.ui.genotypingTable.setItem(row, col_index, item) GraphicalGenotypeController.ui.genotypingTable.setRowHidden( row, True) # Hide empty row else: for col_index, char in enumerate(alleles): item = QTableWidgetItem(char) item.setBackground( GraphicalGenotypeController.colors[char]) # item.setFlags(QtCore.Qt.ItemIsEnabled) GraphicalGenotypeController.ui.genotypingTable.setItem( row, col_index, item) Data.orig_alleles_dict = orig_alleles_dict GraphicalGenotypeController.ui.genotypingTable.cellChanged.connect( GraphicalGenotypeController. cell_changed if not GraphicalGenotypeController.clearing else None)
def update_graphical_genotype_map(updated_alleles_dict, swapped_rows): GraphicalGenotypeController.ui.rename_alleles_btn.setEnabled(False) for index in swapped_rows: data = updated_alleles_dict[index] for i in range(len(data[1])): item = QTableWidgetItem(data[1][i]) color = GraphicalGenotypeController.colors[data[1][i]] if data[1][i] == '1': color.setAlpha(150) if data[1][i] == '0': color.setAlpha(220) item.setBackground(color) # item.setFlags(QtCore.Qt.ItemIsEnabled) GraphicalGenotypeController.ui.genotypingTable.setItem( index, i, item) QMessageBox.information( GraphicalGenotypeController.ui, "Info", str(len(swapped_rows)) + " alleles were renamed successfully.") GraphicalGenotypeController.reset_colors()
def on_view_tb_clicked(self): self.table.clear() # 设置表格列数 self.table.setColumnCount(3) # 设置表格行数 self.table.setRowCount(10) # 隐藏水平表头 # self.tableWidget.horizontalHeader().setVisible(False) self.table.setHorizontalHeaderLabels(['时间', '温度', '湿度']) start_date,end_date = self.get_date() try: query = self.conn.show_data(self.sel_name,start_date,end_date) # j表示行数,i表示列数,d表示 j = 0 while query.next(): # 当数据大于默认的行数时,在最后一行加入一个空行 if j >= self.table.rowCount(): self.table.insertRow(j) for i in range(3): if i == 0: newitem = QTableWidgetItem(str(query.value(0).toString('yyyy/M/d h:mm:ss'))) self.table.setItem(j, i, newitem) elif i == 1: newitem = QTableWidgetItem(str(query.value(1))) if query.value(1) >= self.one_high or query.value(1) <= self.one_low: self.bgbruse = newitem.background() newitem.setBackground(QColor(125, 32, 67)) self.table.setItem(j, i, newitem) # 把数字转换成字符串 else: self.table.setItem(j, i, newitem) elif i == 2: newitem = QTableWidgetItem(str(query.value(2))) if query.value(2) >= self.two_high or query.value(2) <= self.two_low: self.bgbruse = newitem.background() newitem.setBackground(QColor(125, 32, 67)) self.table.setItem(j, i, newitem) # 把数字转换成字符串 else: self.table.setItem(j, i, newitem) j += 1 self.items = {} # 获取总行数 self.set_items(self.table.rowCount()) d = [] wendu = [] shidu = [] for c in range(self.table.rowCount()): # print(self.table.item(c,0).text()) d.append(self.table.item(c,0).text()) wendu.append(self.table.item(c,1).text()) shidu.append(self.table.item(c,2).text()) # self._static_ax.plot(d,wendu) # self._static_ax.plot(d,shidu) # plt.xticks(rotation=45) # plt.plot(d,[30]*len(wendu)) # plt.plot(d,[10]*len(wendu)) # plt.plot(d, wendu) # # plt.plot(d, shidu) # plt.show() for k,v in self.items.items(): self.table.item(v[2] - 1, 0).setBackground(QColor(255, 0, 0)) self.table.item(v[2], 0).setBackground(QColor(0, 255, 0)) self.statusBar.showMessage(f"总共有 {len(self.items)} 处丢失数据") except BaseException as m: # print(m) # print(type(m)) QMessageBox.information(self, "消息框标题", "请先选择一个需要查询的表", )