pyqt-todolist/view/ToDoItem.py

85 lines
2.5 KiB
Python
Raw Normal View History

from PyQt5 import QtGui
2022-04-21 22:42:43 +08:00
from PyQt5.QtCore import Qt, pyqtSignal
2022-04-14 21:22:47 +08:00
from PyQt5.QtGui import QPixmap, QIcon
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
2022-04-21 22:42:43 +08:00
from utils.BasicUtils import change_value
2022-04-14 21:22:47 +08:00
class Button(QPushButton):
trans_signal = pyqtSignal()
def __init__(self):
super(Button, self).__init__()
def mouseReleaseEvent(self, e: QtGui.QMouseEvent) -> None:
self.trans_signal.emit()
# def mousePressEvent(self, QMouseEvent):
# print('haha')
# def clicked(self, checked: bool = ...):
# self.trans_signal.emit()
2022-04-14 21:22:47 +08:00
class ToDoItem(QListWidgetItem):
2022-04-21 22:42:43 +08:00
transaction = pyqtSignal()
2022-04-15 21:33:24 +08:00
"""
:param todo_name : 新建的待办事项名称
2022-04-21 22:42:43 +08:00
:param uid : 待办事项的uid
2022-04-15 21:33:24 +08:00
"""
# todo : 设置点击事件信号传递
2022-04-21 22:42:43 +08:00
def __init__(self, todo_name, uid=None):
2022-04-14 21:22:47 +08:00
super(ToDoItem, self).__init__()
2022-04-21 22:42:43 +08:00
# print('<ToDoItem> 添加的新ToDo' + todo_name)
2022-04-14 21:22:47 +08:00
2022-04-15 21:33:24 +08:00
self.widget = QWidget()
2022-04-14 21:22:47 +08:00
layout = QHBoxLayout()
2022-04-15 21:33:24 +08:00
# self.widget.setMinimumHeight(100)
self.widget.setLayout(layout)
self.widget.show()
2022-04-14 21:22:47 +08:00
self.mark_icon = QPushButton()
2022-04-15 21:33:24 +08:00
self.mark_icon.setObjectName('todo_mark_icon')
2022-04-14 21:22:47 +08:00
self.mark_icon.setIcon(
2022-04-15 21:33:24 +08:00
QIcon(QPixmap('../images/circle.svg').scaled(200, 200, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)))
2022-04-14 21:22:47 +08:00
self.todo_label = QLabel()
2022-04-15 21:33:24 +08:00
self.todo_label.setAlignment(Qt.AlignCenter)
if todo_name:
2022-04-14 21:22:47 +08:00
self.todo_label.setText(str(todo_name))
self.important_button = QPushButton()
2022-04-15 21:33:24 +08:00
self.important_button.setIcon(
2022-04-14 21:22:47 +08:00
QIcon(QPixmap('../images/star_list.svg').scaled(30, 30, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)))
2022-04-15 21:33:24 +08:00
self.important_button.setObjectName('mark_important')
2022-04-14 21:22:47 +08:00
layout.addWidget(self.mark_icon, 2)
layout.addWidget(self.todo_label, 6)
2022-04-15 21:33:24 +08:00
layout.addWidget(self.important_button, 2)
2022-04-21 22:42:43 +08:00
self.mark_icon.clicked.connect(self.set_done)
print('<ToDoItem>', uid)
2022-04-21 22:42:43 +08:00
self.important_button.clicked.connect(lambda: self.set_important(uid))
# self.mark_icon.trans_signal.connect(self.set_done)
2022-04-21 22:42:43 +08:00
def set_done(self):
print('<ToDoItem>hello')
2022-04-21 22:42:43 +08:00
pass
def set_myday(self, uid):
change_value(uid, 'done', True)
pass
def set_important(self, uid):
# important = Important()
# important.load_important.emit()
# self.action.emit()
print('<ToDoItem>',uid)
2022-04-21 22:42:43 +08:00
change_value(uid, 'isImportant', True)
# self.transaction.emit()
pass