From 3aed356b2782042c0c1ff223d2c1bcd501e1e09b Mon Sep 17 00:00:00 2001 From: liyp Date: Fri, 15 Apr 2022 21:33:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0ToDo=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- images/add.svg | 3 -- images/circle.svg | 2 +- images/finish.svg | 1 + resource/current.qss | 47 ++++++++++++++++++++++++++-- view/AddToDoLabel.py | 22 +++++-------- view/HeadDemo.py | 49 ----------------------------- view/HeadDemo.ui | 64 -------------------------------------- view/MyDayView.py | 20 +++++++++--- view/SelfListWidgetItem.py | 2 -- view/ToDoItem.py | 25 ++++++++++----- 10 files changed, 88 insertions(+), 147 deletions(-) delete mode 100644 images/add.svg create mode 100644 images/finish.svg delete mode 100644 view/HeadDemo.py delete mode 100644 view/HeadDemo.ui diff --git a/images/add.svg b/images/add.svg deleted file mode 100644 index 2037b0a..0000000 --- a/images/add.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/images/circle.svg b/images/circle.svg index b275b84..ab091c5 100644 --- a/images/circle.svg +++ b/images/circle.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/images/finish.svg b/images/finish.svg new file mode 100644 index 0000000..c347293 --- /dev/null +++ b/images/finish.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resource/current.qss b/resource/current.qss index efc93b2..dd45ab5 100644 --- a/resource/current.qss +++ b/resource/current.qss @@ -37,8 +37,9 @@ QListWidget::item { font-family: black ; /* border-right: 4px solid rgb(9, 187, 7);*/ } +/*-------begin-------*/ -#todo_list{ +QListWidget#todo_list{ min-width:700px; min-height:650px; border-top-left-radius:3px; @@ -47,6 +48,49 @@ QListWidget::item { border-bottom-right-radius:3px; background-color: rgba(211, 211, 211, 0.5); } +/*添加Item的样式*/ +QListWidget#todo_list::item{ + min-height:60px; +} + +/*被选中时的背景颜色和左边框颜色*/ + +QListWidget#todo_list::item:hover { + background: #eaeaea; +} +QListWidget#todo_list::item:selected { + background: #ffffff; +} +/*#todo_mark_icon{*/ +/* max-width:30px;*/ +/* border-radius:5px;*/ +/*}*/ + +QPushButton#todo_mark_icon,#mark_important { +/* padding: 3px 20px;*/ +/* text-align:center;*/ + background-color:#f3f3f3; + border-radius:15px; + min-width:40px; + max-width:40px; + min-height:40px; +/* max-width:50px;*/ +/* min-height:50px;*/ +} +/*QPushButton#todo_mark_icon:hover {*/ +/* padding: 3px 20px;*/ +/* text-align:center;*/ +/* background-color:#dddddd;*/ +/* border-radius:15px;*/ +/*}*/ +QPushButton#todo_mark_icon:pressed,#mark_important:pressed { +/* padding: 3px 20px;*/ +/* text-align:center;*/ + background-color:#9f9f9f; + border-radius:15px; +} + +/*------end------*/ QLabel#add_todo_label{ width:500px; @@ -65,7 +109,6 @@ QLineEdit#add_line_edit { /* border-bottom-left-radius:3px;*/ /* border-bottom-right-radius:3px;*/ min-width:700px; -/* height:60px;*/ } /*QPushButton {*/ diff --git a/view/AddToDoLabel.py b/view/AddToDoLabel.py index 88bae57..8082777 100644 --- a/view/AddToDoLabel.py +++ b/view/AddToDoLabel.py @@ -14,7 +14,7 @@ class AddToDoAction(QLabel): self.setMinimumWidth(700) layout = QHBoxLayout() # widget.setLayout(layout) - icon = QPixmap('../images/circle.svg').scaled(30, 30, Qt.IgnoreAspectRatio, Qt.SmoothTransformation) + icon = QPixmap('../images/add.png').scaled(30, 30, Qt.IgnoreAspectRatio, Qt.SmoothTransformation) self.icon_label = QLabel() self.icon_label.setPixmap(icon) self.icon_label.setMaximumSize(30, 30) @@ -25,12 +25,8 @@ class AddToDoAction(QLabel): # self.line_edit.clicked.connect(self.line_edit_action) self.line_edit.setObjectName('add_line_edit') self.line_edit.setPlaceholderText('添加任务') - self.line_edit.returnPressed.connect(lambda: self.line_edit_add(self.line_edit.text())) - # self.line_edit.se - # self.line_edit.setEnabled(False) - # self.line_edit. - # todo : QLineEdit点击事件 - # self.line_edit.setAlignment(Qt.AlignLeft) + # 回车事件 + # self.line_edit.returnPressed.connect(lambda: self.line_edit_add(self.line_edit.text())) layout.addWidget(self.icon_label, 1, Qt.AlignLeft) layout.addWidget(self.line_edit, 6, Qt.AlignLeft) @@ -45,10 +41,8 @@ class AddToDoAction(QLabel): # def line_edit_action(self): # print('click left button') - # todo : 回车添加事件 - def line_edit_add(self, name): - self.todo_name.emit(name) - print(name) - self.line_edit.clear() - - # widget.show() + # # 回车添加事件 + # def line_edit_add(self, name): + # self.todo_name.emit(name) + # print(name) + # self.line_edit.clear() diff --git a/view/HeadDemo.py b/view/HeadDemo.py deleted file mode 100644 index 218a6a0..0000000 --- a/view/HeadDemo.py +++ /dev/null @@ -1,49 +0,0 @@ -# -*- coding: utf-8 -*- - -# Form implementation generated from reading ui file 'HeadDemo.ui' -# -# Created by: PyQt5 UI code generator 5.15.6 -# -# WARNING: Any manual changes made to this file will be lost when pyuic5 is -# run again. Do not edit this file unless you know what you are doing. - - -from PyQt5 import QtCore, QtGui, QtWidgets - - -class Ui_Form(object): - def setupUi(self, Form): - Form.setObjectName("Form") - Form.resize(400, 300) - self.widget = QtWidgets.QWidget(Form) - self.widget.setGeometry(QtCore.QRect(40, 90, 276, 90)) - self.widget.setObjectName("widget") - self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget) - self.horizontalLayout.setContentsMargins(0, 0, 0, 0) - self.horizontalLayout.setObjectName("horizontalLayout") - self.verticalLayout_2 = QtWidgets.QVBoxLayout() - self.verticalLayout_2.setObjectName("verticalLayout_2") - self.label = QtWidgets.QLabel(self.widget) - font = QtGui.QFont() - font.setPointSize(32) - self.label.setFont(font) - self.label.setObjectName("label") - self.verticalLayout_2.addWidget(self.label) - self.label_2 = QtWidgets.QLabel(self.widget) - self.label_2.setObjectName("label_2") - self.verticalLayout_2.addWidget(self.label_2) - self.horizontalLayout.addLayout(self.verticalLayout_2) - self.pushButton = QtWidgets.QPushButton(self.widget) - self.pushButton.setStyleSheet("") - self.pushButton.setObjectName("pushButton") - self.horizontalLayout.addWidget(self.pushButton) - - self.retranslateUi(Form) - QtCore.QMetaObject.connectSlotsByName(Form) - - def retranslateUi(self, Form): - _translate = QtCore.QCoreApplication.translate - Form.setWindowTitle(_translate("Form", "Form")) - self.label.setText(_translate("Form", "我的一天")) - self.label_2.setText(_translate("Form", "2022-04-12")) - self.pushButton.setText(_translate("Form", "PushButton")) diff --git a/view/HeadDemo.ui b/view/HeadDemo.ui deleted file mode 100644 index eee88d3..0000000 --- a/view/HeadDemo.ui +++ /dev/null @@ -1,64 +0,0 @@ - - - Form - - - - 0 - 0 - 400 - 300 - - - - Form - - - - - 40 - 90 - 276 - 90 - - - - - - - - - - 32 - - - - 我的一天 - - - - - - - 2022-04-12 - - - - - - - - - - - - PushButton - - - - - - - - - diff --git a/view/MyDayView.py b/view/MyDayView.py index 07dc9a3..4d61a25 100644 --- a/view/MyDayView.py +++ b/view/MyDayView.py @@ -5,6 +5,7 @@ from PyQt5.QtCore import Qt from view.AddToDoLabel import AddToDoAction from view.MyDayHeadLabel import HeadLabel +from view.ToDoItem import ToDoItem class MyDay(QWidget): @@ -35,12 +36,14 @@ class MyDay(QWidget): head_widget.setAttribute(Qt.WA_StyledBackground) self.todo_list = QListWidget() + self.todo_list.setFrameShape(QListWidget.NoFrame) self.todo_list.setObjectName('todo_list') # 添加ToDo的标签 self.add_todo = AddToDoAction() + self.add_todo.line_edit.returnPressed.connect(lambda: self.line_edit_add(self.add_todo.line_edit.text())) self.add_todo.setAlignment(Qt.AlignCenter) - self.add_todo.todo_name.connect(self.add_todo_action) + # self.add_todo.todo_name.connect(self.add_todo_action) # head_widget.setPalette(palette) @@ -97,14 +100,23 @@ class MyDay(QWidget): def menu_action(self, count): # 点击按钮 - self.setStyleSheet('#my_day{background-image:url("../images/3.jpg");' + self.setStyleSheet('#my_day{background-image:url("../images/4.jpg");' 'background-position: center; border-radius: 10px;' '}') self.head_label.show() print('选中:' + count) + # + # def add_todo_action(self, name): + # print(name) + # todo : 回车添加事件 + def line_edit_add(self, name): + self.add_todo.todo_name.emit(name) + # print('添加的新ToDo:' + name) + todo_item = ToDoItem(name) + self.todo_list.addItem(todo_item) + self.todo_list.setItemWidget(todo_item, todo_item.widget) - def add_todo_action(self, name): - print(name) + self.add_todo.line_edit.clear() diff --git a/view/SelfListWidgetItem.py b/view/SelfListWidgetItem.py index ffee232..eb82a10 100644 --- a/view/SelfListWidgetItem.py +++ b/view/SelfListWidgetItem.py @@ -37,7 +37,6 @@ class SelfListWidgetItem(QListWidgetItem): # print(self.item_name) self.item_name_label.setObjectName('item_name_label') - layout.addWidget(self.item_name_label, 3) if self.todo_count: @@ -51,4 +50,3 @@ class SelfListWidgetItem(QListWidgetItem): layout.addWidget(self.todo_count_label, 1) # 设置自定义的QListWidgetItem的sizeHint,不然无法显示 self.setSizeHint(self.widget.sizeHint()) - diff --git a/view/ToDoItem.py b/view/ToDoItem.py index 59795dd..e3650a4 100644 --- a/view/ToDoItem.py +++ b/view/ToDoItem.py @@ -5,23 +5,32 @@ from PyQt5.QtCore import Qt class ToDoItem(QListWidgetItem): + """ + :param todo_name : 新建的待办事项名称 + """ + def __init__(self, todo_name): super(ToDoItem, self).__init__() + print('添加的新ToDo:' + todo_name) - widget = QWidget(self) + self.widget = QWidget() layout = QHBoxLayout() - widget.setLayout(layout) - widget.show() + + # 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(30, 30, Qt.IgnoreAspectRatio, Qt.SmoothTransformation))) + QIcon(QPixmap('../images/circle.svg').scaled(200, 200, Qt.IgnoreAspectRatio, Qt.SmoothTransformation))) self.todo_label = QLabel() - if not todo_name: + self.todo_label.setAlignment(Qt.AlignCenter) + if todo_name: self.todo_label.setText(str(todo_name)) self.important_button = QPushButton() - self.mark_icon.setIcon( + 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) + layout.addWidget(self.important_button, 2)