Commit ab29cbac authored by Tom Pillot's avatar Tom Pillot
Browse files

Replace the list view by a table view

parent 3109620e
......@@ -3,7 +3,6 @@ import cv2
class Detector(apriltag.Detector):
def __init__(self):
super().__init__()
self.DECISION_MARGIN = 40
......
import sys
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtCore as qtc
from PyQt5 import QtGui as qtg
from detector import Detector
tag_ids = {}
class AlignDelegate(qtw.QStyledItemDelegate):
def initStyleOption(self, option, index):
super(AlignDelegate, self).initStyleOption(option, index)
option.displayAlignment = qtc.Qt.AlignCenter
class MainWindow(qtw.QWidget):
NAME, TAG = range(2)
def __init__(self, *args, **kargs):
super().__init__(*args, **kargs)
self.detector = Detector()
self.tag_ids = {}
self.setWindowTitle("Liste des équipes")
self.list_view = qtw.QListWidget()
self.table_view = qtw.QTableView()
self.table_view.setEditTriggers(qtw.QAbstractItemView.NoEditTriggers)
self.table_view.horizontalHeader().setSectionResizeMode(qtw.QHeaderView.Stretch)
self.table_view.verticalHeader().setVisible(False)
# Align text to the center
delegate = AlignDelegate(self.table_view)
self.table_view.setItemDelegate(delegate)
self.tree_model = qtg.QStandardItemModel(0, 2, self.table_view)
self.tree_model.setHeaderData(self.NAME, qtc.Qt.Horizontal, "Nom")
self.tree_model.setHeaderData(self.TAG, qtc.Qt.Horizontal, "Tag")
self.table_view.setModel(self.tree_model)
self.name_input = qtw.QLineEdit()
self.tag_label = qtw.QLabel("")
self.add_button = qtw.QPushButton("Ajouter")
......@@ -40,7 +61,7 @@ class MainWindow(qtw.QWidget):
hlayout4.addWidget(self.delete_button)
vlayout = qtw.QVBoxLayout()
vlayout.addWidget(self.list_view)
vlayout.addWidget(self.table_view)
vlayout.addLayout(hlayout1)
vlayout.addLayout(hlayout3)
vlayout.addLayout(hlayout4)
......@@ -62,24 +83,28 @@ class MainWindow(qtw.QWidget):
if self.tag_label.text() and self.name_input.text():
tag_id = int(self.tag_label.text())
name = self.name_input.text()
self.list_view.addItem(name)
self.tree_model.insertRow(0)
self.tree_model.setData(self.tree_model.index(0, self.NAME), name)
self.tree_model.setData(self.tree_model.index(0, self.TAG), tag_id)
self.tag_label.setText("")
self.name_input.setText("")
tag_ids[name] = tag_id
self.tag_ids[name] = tag_id
def edit_team(self):
selected = self.list_view.selectedItems()
selected = self.table_view.selectedIndexes()
if selected:
name = selected[0].text()
tag_id = tag_ids[name]
item = selected[0]
name = self.tree_model.data(self.tree_model.index(item.row(), self.NAME))
tag_id = self.tree_model.data(self.tree_model.index(item.row(), self.TAG))
self.tag_label.setText(str(tag_id))
self.name_input.setText(name)
self.tree_model.takeRow(item.row())
def delete_team(self):
selected = self.list_view.selectedItems()
for item in selected:
print(item)
self.list_view.takeItem(self.list_view.row(item))
selected = self.table_view.selectedIndexes()
if selected:
item = selected[0]
self.tree_model.takeRow(item.row())
if __name__ == '__main__':
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment