统一布局头部标签位置

This commit is contained in:
liyp 2022-04-14 16:19:59 +08:00
parent 4a055e99fd
commit 42bfede368
5 changed files with 69 additions and 12 deletions

View file

@ -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);

View file

@ -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;')

27
view/AddToDoLabel.py Normal file
View file

@ -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()

View file

@ -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)

View file

@ -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')))