pyqt-todolist/view/ToDoItem.py

84 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from PyQt5 import QtGui
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QPixmap, QIcon
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from utils.BasicUtils import change_value
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()
class ToDoItem(QListWidgetItem):
transaction = pyqtSignal()
"""
:param todo_name : 新建的待办事项名称
:param uid : 待办事项的uid
"""
# todo : 设置点击事件信号传递
def __init__(self, todo_name, uid=None):
super(ToDoItem, self).__init__()
# print('<ToDoItem> 添加的新ToDo' + todo_name)
self.widget = QWidget()
layout = QHBoxLayout()
# self.widget.setMinimumHeight(100)
self.widget.setLayout(layout)
self.widget.show()
self.mark_icon = QPushButton()
self.mark_icon.setObjectName('todo_mark_icon')
self.mark_icon.setIcon(
QIcon(QPixmap('../images/circle.svg').scaled(200, 200, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)))
self.todo_label = QLabel()
self.todo_label.setAlignment(Qt.AlignCenter)
if todo_name:
self.todo_label.setText(str(todo_name))
self.important_button = QPushButton()
self.important_button.setIcon(
QIcon(QPixmap('../images/star_list.svg').scaled(30, 30, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)))
self.important_button.setObjectName('mark_important')
layout.addWidget(self.mark_icon, 2)
layout.addWidget(self.todo_label, 6)
layout.addWidget(self.important_button, 2)
self.mark_icon.clicked.connect(self.set_done)
print('<ToDoItem>', uid)
self.important_button.clicked.connect(lambda: self.set_important(uid))
# self.mark_icon.trans_signal.connect(self.set_done)
def set_done(self):
print('<ToDoItem>hello')
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)
change_value(uid, 'isImportant', True)
# self.transaction.emit()
pass