在3个不同的QlistWidget中显示来自SQLITE数据库的信息
我的目标是每天显示一张看板桌,以便用户可以在日历中每天进行处理或完成的任务。我的程序的外观如下:
每个列表都是qlistwidget,用户可以在其中添加新的待处理任务右键单击它们或将任务从“ Pendientes”列表移动到“ en proceso”列表或“完整列表”列表。 现在,为了保存qcalendarwidget的每个日期的任务,我正在尝试使用一个看起来像这样的sqlite数据库:
“ tareas”列显示任务,“ Lista”显示了与我的三个QlistWidgets相对应的数字(0 =“ pendientes”; 1 =“ en proceso”和2 =“ pleastadas”)和“ pleastadas”)和“ fecha”)和“ fecha”显示日期。我能够按日期显示相应列表中的每个任务,但只有我直接在SQLite浏览器中添加的任务:
def updateTaskList(self, date):
self.lista_pendientes.clear()
self.lista_enprogreso.clear()
self.lista_completadas.clear()
db = sqlite3.connect("todo.db")
cursor = db.cursor()
query = "SELECT tarea, lista FROM tareas WHERE fecha = ?"
row = (date,)
results = cursor.execute(query, row).fetchall()
for tarea, list in results:
item = QListWidgetItem(tarea)
if list == 0:
self.lista_pendientes.addItem(item)
elif list == 1:
self.lista_enprogreso.addItem(item)
elif list == 2:
self.lista_completadas.addItem(item)
但是当我尝试保存从程序中添加的任务时, t保存更改:
def saveChanges (self):
db = sqlite3.connect("todo.db")
cursor = db.cursor()
date = self.calendarWidget.selectedDate().toPython()
for i in range(self.lista_pendientes.count()):
item = self.lista_pendientes.item(i)
task = item.text()
query = "UPDATE tareas SET lista = '0' WHERE tarea = ? AND fecha = ? "
row = (task, date,)
cursor.execute(query,row)
db.commit()
在此功能中,我试图仅通过将索引0分配给这些任务,但无济于事,仅保存“ Pendientes”列表中的任务。我该怎么做才能从数据库中的三个QListWidgets保存任务?
编辑解决 进行了一些尝试后,我建立了一个更容易的解决方案:在每种类型的任务中使用SQLite数据库中的三个不同表。这样,我就可以单独保存每个任务,而不必担心列表列。
My objective is to show a kanban table by day, so the user could save their pending, in process or completed tasks for each day in the calendar. My program look as follows:
Every list is a QListWidget, where the user can add a new pending task by right clicking over them or move the tasks from the "Pendientes" list to the "En proceso" list or the "Completadas" list.
Now, for saving the task for every date of the QCalendarWidget, I'm trying to use a sqlite database that looks like this:
where the "tareas" column shows the tasks, "lista" shows a number corresponding to each of my three QListWidgets (0 = "Pendientes"; 1 = "En proceso" and 2 = "Completadas") and "fecha" shows the date. I'm able to show every task in the corresponding list by date just fine with this function, but only the tasks that I added directly in the Sqlite Browser:
def updateTaskList(self, date):
self.lista_pendientes.clear()
self.lista_enprogreso.clear()
self.lista_completadas.clear()
db = sqlite3.connect("todo.db")
cursor = db.cursor()
query = "SELECT tarea, lista FROM tareas WHERE fecha = ?"
row = (date,)
results = cursor.execute(query, row).fetchall()
for tarea, list in results:
item = QListWidgetItem(tarea)
if list == 0:
self.lista_pendientes.addItem(item)
elif list == 1:
self.lista_enprogreso.addItem(item)
elif list == 2:
self.lista_completadas.addItem(item)
But when I try to save the tasks that I added from my program it doesn't save the changes:
def saveChanges (self):
db = sqlite3.connect("todo.db")
cursor = db.cursor()
date = self.calendarWidget.selectedDate().toPython()
for i in range(self.lista_pendientes.count()):
item = self.lista_pendientes.item(i)
task = item.text()
query = "UPDATE tareas SET lista = '0' WHERE tarea = ? AND fecha = ? "
row = (task, date,)
cursor.execute(query,row)
db.commit()
In this function I'm trying to save only the tasks that are in the "pendientes" list, by assigning the index 0 to those tasks, but to no avail. What could I do to save the tasks from the three QListWidgets in my database?
EDIT-SOLVED
After experimenting a bit I founded an easier solution: to use three different tables in my sqlite database for each type of task. That way I can save each task individually without worrying about the list column.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论