pyqt-todolist/view/MyDayView.py

112 lines
4.4 KiB
Python
Raw Normal View History

2022-04-07 21:11:37 +08:00
import os
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
2022-04-14 16:19:59 +08:00
from view.AddToDoLabel import AddToDoAction
2022-04-12 21:34:18 +08:00
from view.MyDayHeadLabel import HeadLabel
from view.ChangeThemeLabel import ChangeTheme
2022-04-07 21:11:37 +08:00
class MyDay(QWidget):
def __init__(self, parent=None):
2022-04-07 21:11:37 +08:00
super(MyDay, self).__init__()
2022-04-12 21:34:18 +08:00
self.setObjectName('my_day')
2022-04-14 16:19:59 +08:00
self.setStyleSheet('#my_day{background-image:url("../images/10.jpg");border-radius: 10px;}')
2022-04-12 21:34:18 +08:00
self.setAttribute(Qt.WA_StyledBackground)
# 下面这一句有问题,需要修复修改主题的实现方法
# self.setStyleSheet('#my_day{background-image:url("../images/2.jpg");')
# 无效
# palette = QPalette()
# palette.setBrush(QPalette.Background,
# QBrush(QPixmap(os.getcwd() + "/../images/0.jpg").scaled(self.width(), self.height())))
# self.setPalette(palette)
2022-04-07 21:11:37 +08:00
# 布局样式:最外面一个大的垂直布局,里面的最上面标题是一个水平布局,水平布局显示的是一个垂直布局和一个右边的选项,用来更换背景
2022-04-12 21:34:18 +08:00
# 布局样式继承QWidget,里面一个垂直布局最上面一个QWidget用来设置头部布局
# 头部QWidget里面一个水平布局水平布局里面一个QWidget方便设置整体位置然后是一个
2022-04-14 16:19:59 +08:00
layout = QVBoxLayout() # 总布局
head_layout = QHBoxLayout() # 头部总布局
2022-04-12 21:34:18 +08:00
head_widget = QWidget(self)
2022-04-14 16:19:59 +08:00
head_widget.setMinimumHeight(175)
head_widget.setMaximumHeight(200)
2022-04-12 21:34:18 +08:00
head_widget.setAttribute(Qt.WA_StyledBackground)
self.todo_list = QListWidget()
self.todo_list.setObjectName('todo_list')
2022-04-12 21:34:18 +08:00
2022-04-14 16:19:59 +08:00
self.add_todo = AddToDoAction()
self.add_todo.setAlignment(Qt.AlignBottom)
2022-04-12 21:34:18 +08:00
# head_widget.setPalette(palette)
head_widget.setLayout(head_layout)
head_layout.setAlignment(Qt.AlignCenter)
# head_left_layout = QVBoxLayout()
layout.addWidget(head_widget, 2, Qt.AlignTop)
2022-04-14 16:19:59 +08:00
self.head_label = HeadLabel()
layout.addWidget(self.todo_list, 6, Qt.AlignCenter | Qt.AlignTop)
2022-04-14 16:19:59 +08:00
head_layout.addWidget(self.head_label, 8)
# todo : 修改布局
layout.addWidget(self.add_todo, 2, Qt.AlignHCenter)
2022-04-12 21:34:18 +08:00
self.menu_image = QPushButton()
self.menu_image.setObjectName('menu_image')
self.menu_image.setFixedSize(30, 30)
2022-04-12 21:34:18 +08:00
# self.menu_image.setScaledContents(True)
pic_btn = QPixmap(os.getcwd() + "/../images/menu.png")
self.menu_image.setIcon(QIcon(pic_btn))
# self.menu_image.setFixedSize(QPixmap(os.getcwd() + "/../images/menu.png").size())
# head_layout.addLayout(head_left_layout)
head_layout.addWidget(self.menu_image, 2)
2022-04-12 21:34:18 +08:00
head_layout.addStretch(1)
2022-04-07 21:11:37 +08:00
self.setLayout(layout)
# self.menu_image.clicked.connect(self.menu_action)
button_menu = QMenu(self)
# 背景透明
button_menu.setAttribute(Qt.WA_TranslucentBackground)
# 无边框、去掉自带阴影
button_menu.setWindowFlags(
button_menu.windowFlags() | Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint)
self.menu_image.setMenu(button_menu)
theme_label = QAction(self)
theme_label.setText('主题')
theme_label.setDisabled(True)
button_menu.addAction(theme_label)
button_menu.addSeparator()
# button_menu
for i in range(11):
label_action = QAction(self)
label_action.setIcon(QIcon('../images/' + str(i) + '.jpg'))
label_action.setText(str(i))
label_action.triggered.connect(lambda: self.menu_action(str(i)))
button_menu.addAction(label_action)
# pass
2022-04-12 21:34:18 +08:00
# todo : 下面的方法实现点击更换主题的功能
def menu_action(self, count):
# 点击按钮
# self.menu_label = ChangeTheme()
self.setStyleSheet('#my_day{background-image:url("../images/3.jpg");'
'background-position: center; border-radius: 10px;'
2022-04-14 16:19:59 +08:00
' padding-top:170px;}')
self.head_label.show()
print('选中:' + count)
# self.palette = QPalette()
# self.palette.setBrush(self.palette.Background, QBrush(QPixmap('../images/' + count + '.png')))
# self.setPalette(self.palette)
pass