From 42bfede36860950cf78e1def8fd24afe6d767658 Mon Sep 17 00:00:00 2001 From: liyp Date: Thu, 14 Apr 2022 16:19:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=B8=83=E5=B1=80=E5=A4=B4?= =?UTF-8?q?=E9=83=A8=E6=A0=87=E7=AD=BE=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resource/current.qss | 13 ++++++++++--- view/AddListLabel.py | 8 ++++++++ view/AddToDoLabel.py | 27 +++++++++++++++++++++++++++ view/MyDayHeadLabel.py | 7 ++++++- view/MyDayView.py | 26 ++++++++++++++++++-------- 5 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 view/AddToDoLabel.py diff --git a/resource/current.qss b/resource/current.qss index ed37691..4139db3 100644 --- a/resource/current.qss +++ b/resource/current.qss @@ -1,8 +1,10 @@ /*去掉item虚线边框*/ -/** {*/ +* { /* background: #f3f3f3;*/ /* color: black ;*/ -/*}*/ +padding:0px; +margin:0px; +} QListWidget, QListView, QTreeWidget, QTreeView { outline-style: 0px; @@ -40,6 +42,10 @@ QListWidget::item { min-width:700px; background-color: rgba(211, 211, 211, 0.5); } + +#add_todo_label{ + width:500px; +} /*QPushButton {*/ /* max-width: 120px;*/ /* color: white;*/ @@ -75,7 +81,7 @@ QPushButton#menu_image:hover { QPushButton#menu_image:pressed { /* padding: 3px 20px;*/ /* text-align:center;*/ - background-color:#d4d4d4; + background-color:#9f9f9f; border-radius:15px; } @@ -161,6 +167,7 @@ QLabel#head_label{ /*隐藏按钮右侧的下拉三角*/ QPushButton::menu-indicator{ image:none;} + QMenu { /* 半透明效果 */ background-color: rgba(255, 255, 255, 230); diff --git a/view/AddListLabel.py b/view/AddListLabel.py index 89dfa3c..24f55ca 100644 --- a/view/AddListLabel.py +++ b/view/AddListLabel.py @@ -20,3 +20,11 @@ class AddListAction(QLabel): self.add_text = QLabel("新建列表") layout.addWidget(self.add_image, 3) layout.addWidget(self.add_text, 4) + + def mousePressEvent(self, QMouseEvent): + print('按下QLabel') + self.setStyleSheet('background-color:#9f9f9f;') + + def mouseReleaseEvent(self, QMouseEvent): + print('释放QLabel') + self.setStyleSheet('background-color:#eaeaea;') diff --git a/view/AddToDoLabel.py b/view/AddToDoLabel.py new file mode 100644 index 0000000..c8f3918 --- /dev/null +++ b/view/AddToDoLabel.py @@ -0,0 +1,27 @@ +from PyQt5.QtWidgets import * +from PyQt5.QtGui import QPixmap +from PyQt5.QtCore import Qt + + +class AddToDoAction(QLabel): + def __init__(self): + super(AddToDoAction, self).__init__() + self.setObjectName('add_todo_label') + # widget = QWidget(self) + # widget.setMinimumWidth(500) + layout = QHBoxLayout() + # widget.setLayout(layout) + icon = QLabel() + icon.setPixmap(QPixmap('../images/circle.svg').scaled(50,50)) + self.line_edit=QLineEdit() + self.line_edit.setPlaceholderText('添加任务') + + layout.addWidget(icon, 1, Qt.AlignLeft) + layout.addWidget(self.line_edit,6,Qt.AlignCenter) + + self.setScaledContents(True) + + # self.sizeHint() + self.setLayout(layout) + + # widget.show() diff --git a/view/MyDayHeadLabel.py b/view/MyDayHeadLabel.py index 2269d71..7adc86a 100644 --- a/view/MyDayHeadLabel.py +++ b/view/MyDayHeadLabel.py @@ -10,6 +10,7 @@ class HeadLabel(QLabel): self.setScaledContents(True) self.setObjectName('head_label') layout = QVBoxLayout() + self.setMinimumHeight(170) # 设置当前时间 weekday = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"] @@ -21,14 +22,18 @@ class HeadLabel(QLabel): # print(str(month) + '月' + str(day) + '日,' + weekday[weekday_index]) self.title = QLabel("我的一天") + self.title.setStyleSheet('font-weight:bold;color:white;margin:0px') + # self.title.setObjectName('title') # 设置字体大小 self.font = QFont() self.font.setPointSize(32) self.title.setFont(self.font) - # todo: 需要调整布局,修复字体溢出 + # todo: 需要调整布局,修复字体间距 # self.title.setObjectName('title') self.time_label = QLabel(str(month) + '月' + str(day) + '日,' + weekday[weekday_index]) + self.time_label.setStyleSheet('color:white;') + # self.time_label.setObjectName('time_label') layout.addWidget(self.title) layout.addWidget(self.time_label) diff --git a/view/MyDayView.py b/view/MyDayView.py index d9385ae..cfb7586 100644 --- a/view/MyDayView.py +++ b/view/MyDayView.py @@ -3,6 +3,8 @@ import sys from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt + +from view.AddToDoLabel import AddToDoAction from view.MyDayHeadLabel import HeadLabel from view.ChangeThemeLabel import ChangeTheme @@ -11,10 +13,9 @@ class MyDay(QWidget): def __init__(self, parent=None): super(MyDay, self).__init__() self.setObjectName('my_day') - self.setStyleSheet('#my_day{background-image:url("../images/10.jpg")}') + self.setStyleSheet('#my_day{background-image:url("../images/10.jpg");border-radius: 10px;}') self.setAttribute(Qt.WA_StyledBackground) - # todo : 使用网格布局设置背景图 # 下面这一句有问题,需要修复修改主题的实现方法 # self.setStyleSheet('#my_day{background-image:url("../images/2.jpg");') # 无效 @@ -26,16 +27,21 @@ class MyDay(QWidget): # 布局样式:最外面一个大的垂直布局,里面的最上面标题是一个水平布局,水平布局显示的是一个垂直布局和一个右边的选项,用来更换背景 # 布局样式:继承QWidget,里面一个垂直布局,最上面一个QWidget用来设置头部布局 # 头部QWidget里面一个水平布局,水平布局里面一个QWidget(方便设置整体位置),然后是一个 - layout = QVBoxLayout() - head_layout = QHBoxLayout() + layout = QVBoxLayout() # 总布局 + head_layout = QHBoxLayout() # 头部总布局 head_widget = QWidget(self) - head_widget.setMaximumHeight(100) + head_widget.setMinimumHeight(175) + + head_widget.setMaximumHeight(200) head_widget.setAttribute(Qt.WA_StyledBackground) self.todo_list = QListWidget() self.todo_list.setObjectName('todo_list') + self.add_todo = AddToDoAction() + self.add_todo.setAlignment(Qt.AlignBottom) + # head_widget.setPalette(palette) head_widget.setLayout(head_layout) @@ -43,9 +49,11 @@ class MyDay(QWidget): # head_left_layout = QVBoxLayout() layout.addWidget(head_widget, 2, Qt.AlignTop) - head_label = HeadLabel() + self.head_label = HeadLabel() layout.addWidget(self.todo_list, 6, Qt.AlignCenter | Qt.AlignTop) - head_layout.addWidget(head_label, 8) + head_layout.addWidget(self.head_label, 8) + # todo : 修改布局 + layout.addWidget(self.add_todo, 2, Qt.AlignHCenter) self.menu_image = QPushButton() self.menu_image.setObjectName('menu_image') @@ -92,7 +100,9 @@ class MyDay(QWidget): # self.menu_label = ChangeTheme() self.setStyleSheet('#my_day{background-image:url("../images/3.jpg");' 'background-position: center; border-radius: 10px;' - ' padding-top:40px;}') + ' padding-top:170px;}') + self.head_label.show() + print('选中:' + count) # self.palette = QPalette() # self.palette.setBrush(self.palette.Background, QBrush(QPixmap('../images/' + count + '.png')))