From ff13cd521c3bbe3a203a5224b4a3ce598b5feea1 Mon Sep 17 00:00:00 2001 From: liyp Date: Thu, 7 Apr 2022 19:34:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=E5=B8=83?= =?UTF-8?q?=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- images/exit.svg | 1 + main/main.py | 58 +++++++++++++++++-------------------- resource/current.qss | 22 +++++++------- test/qstackedlauout.py | 3 +- view/AddListLabel.py | 19 ++++++++++-- view/SelfListWidgetItem.py | 6 +--- view/UserLabel.py | 59 +++++++++----------------------------- 7 files changed, 71 insertions(+), 97 deletions(-) create mode 100644 images/exit.svg diff --git a/images/exit.svg b/images/exit.svg new file mode 100644 index 0000000..2bbe915 --- /dev/null +++ b/images/exit.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/main/main.py b/main/main.py index ecbf1a8..7df5557 100644 --- a/main/main.py +++ b/main/main.py @@ -1,12 +1,12 @@ import os import sys - from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt from utils.QSSLoader import QSSLoader from view.UserLabel import User from view.SelfListWidgetItem import SelfListWidgetItem +from view.AddListLabel import AddListAction class MainWidget(QWidget): @@ -18,29 +18,26 @@ class MainWidget(QWidget): # 子布局,左边的部分 self.sub_layout = QVBoxLayout() self.sub_layout.spacing() - self.sub_layout.addWidget(self.user_label, 1) + self.sub_layout.addWidget(self.user_label, 2) # 左侧列表 self.system_listWidget = QListWidget(self) - self.sub_layout.addWidget(self.system_listWidget, 2) + self.sub_layout.addWidget(self.system_listWidget, 15) # 可自定义添加的listWidget - self.self_listWidget = QListWidget(self) - self.sub_layout.addWidget(self.self_listWidget, 7) + # self.custom = QListWidget(self) + # self.sub_layout.addWidget(self.custom, 7) - # todo - # 需要把下面的重写QLabel解决问题,单个QLabel无法解决问题 + # todo : 需要把下面的重写QLabel解决问题,单个QLabel无法解决问题 + self.add_list_action = AddListAction() - self.add_item_label = QLabel('新建列表') - self.add_item_label.setMaximumHeight(50) - self.add_item_label.setObjectName('add_item_label') # self.add_item_label.setPixmap(QPixmap()) - self.sub_layout.addWidget(self.add_item_label, 1) + self.sub_layout.addWidget(self.add_list_action, 1) # 禁止双击可编辑 - self.self_listWidget.setEditTriggers(QAbstractItemView.NoEditTriggers) + # self.custom.setEditTriggers(QAbstractItemView.NoEditTriggers) # 右键菜单 - self.self_listWidget.setContextMenuPolicy(Qt.CustomContextMenu) - self.self_listWidget.setObjectName('self_listWidget') - self.self_listWidget.customContextMenuRequested.connect(self.myListWidgetContext) + # self.custom.setContextMenuPolicy(Qt.CustomContextMenu) + # self.custom.setObjectName('custom') + # self.custom.customContextMenuRequested.connect(self.myListWidgetContext) # 右侧层叠窗口 self.stackedWidget = QStackedWidget(self) @@ -65,14 +62,13 @@ class MainWidget(QWidget): self.system_listWidget.addItem(self.important) self.system_listWidget.setItemWidget(self.important, self.important.widget) - self.two_day = SelfListWidgetItem('我的一天', 1, os.getcwd() + '/../images/sun.svg') - self.self_listWidget.addItem(self.two_day) - self.self_listWidget.setItemWidget(self.two_day, self.two_day.widget) + # 测试添加下面的 + # self.two_day = SelfListWidgetItem('我的一天', 1, os.getcwd() + '/../images/sun.svg') + # self.custom.addItem(self.two_day) + # self.custom.setItemWidget(self.two_day, self.two_day.widget) + # self.custom. - pass - - # todo - # 仔细研究右键菜单 + # todo 仔细研究右键菜单 def myListWidgetContext(self, position): # 设置右键菜单 @@ -85,14 +81,14 @@ class MainWidget(QWidget): # 查看右键时是否在item上面,如果不在.就不显示删除和修改. pop_menu.addAction(rename_action) - if self.self_listWidget.itemAt(position): + if self.custom.itemAt(position): pop_menu.addAction(del_action) pop_menu.addAction(rename_action) rename_action.triggered.connect(self.RenameItem) copy_action.triggered.connect(self.CreateNewItem) del_action.triggered.connect(self.DeleteItem) - pop_menu.exec_(self.self_listWidget.mapToGlobal(position)) + pop_menu.exec_(self.custom.mapToGlobal(position)) # 创建新的分组 def CreateNewItem(self): @@ -101,21 +97,21 @@ class MainWidget(QWidget): item.setTextAlignment(Qt.AlignCenter) # 使得item是可以编辑的. item.setFlags(item.flags() | Qt.ItemIsEditable) - self.self_listWidget.addItem(item) + self.custom.addItem(item) # 创建后就可以编辑item,用户自己起名字. - self.self_listWidget.editItem(item) + self.custom.editItem(item) # 删除分组 def DeleteItem(self): - self.self_listWidget.takeItem(self.self_listWidget.currentRow()) + self.custom.takeItem(self.custom.currentRow()) # 重命名分组 def RenameItem(self): - curRow = self.self_listWidget.currentRow() - item = self.self_listWidget.item(curRow) + curRow = self.custom.currentRow() + item = self.custom.item(curRow) item.setFlags(item.flags() | Qt.ItemIsEditable) - self.self_listWidget.editItem(item) - self.self_listWidget.itemChanged.connect(lambda: self.ChangeItem(item)) + self.custom.editItem(item) + self.custom.itemChanged.connect(lambda: self.ChangeItem(item)) def ChangeItem(self, item): print("test") diff --git a/resource/current.qss b/resource/current.qss index b68d8bd..1e93c64 100644 --- a/resource/current.qss +++ b/resource/current.qss @@ -1,12 +1,11 @@ /*去掉item虚线边框*/ -* { +/** {*/ /* background: #f3f3f3;*/ - color: black ; -} +/* color: black ;*/ +/*}*/ QListWidget, QListView, QTreeWidget, QTreeView { outline-style: 0px; - } /*设置左侧选项的最小最大宽度,文字颜色和背景颜色*/ QListWidget { @@ -20,7 +19,8 @@ QListWidget { /*被选中时的背景颜色和左边框颜色*/ QListWidget::item:selected { background: #eaeaea; - border-left: 4px solid rgb(9, 187, 7); + border-left: 5px solid rgb(9, 187, 7); +/* border-left-width:10px;*/ } /*鼠标悬浮时的背景颜色*/ @@ -69,7 +69,7 @@ QListWidget::item { /*右侧的层叠窗口的背景颜色*/ QStackedWidget { - color:snow; + color:black; /* background: black;*/ } /*todo_count_label 气泡效果*/ @@ -93,12 +93,12 @@ QLabel#menu{ padding-right:10px; } /*主界面最下面的添加*/ -QLabel#add_item_label{ - text-align:right; - background:url(../images/add.png) ; - background-repeat:0; - +QLabel#AddListAction::hover{ +/* text-align:center;*/ + background: #eaeaea; +/* padding-right:25px;*/ } + /*QLineEdit {*/ /* border: 2px solid rgb(52,52,52);*/ /* border-top-left-radius:10px; */ diff --git a/test/qstackedlauout.py b/test/qstackedlauout.py index 56b639b..22d4215 100644 --- a/test/qstackedlauout.py +++ b/test/qstackedlauout.py @@ -1,7 +1,6 @@ import sys -from PyQt5 import QtCore, QtGui, QtWidgets + from PyQt5.QtCore import Qt -from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import (QApplication, QMainWindow, QStackedLayout, QWidget, QToolBar, QToolButton, QStyle, QColorDialog, QFontDialog, QVBoxLayout, QGroupBox, QRadioButton) diff --git a/view/AddListLabel.py b/view/AddListLabel.py index 834c760..935acf4 100644 --- a/view/AddListLabel.py +++ b/view/AddListLabel.py @@ -1,9 +1,22 @@ +import os + from PyQt5.QtGui import * from PyQt5.QtWidgets import * -from PyQt5.QtCore import Qt -class AddList(QLabel): +class AddListAction(QLabel): def __init__(self): - super(AddList, self).__init__() + super(AddListAction, self).__init__() self.widget = QWidget(self) + self.widget.setMaximumHeight(50) + self.setObjectName('AddListAction') + layout = QHBoxLayout() + self.widget.setLayout(layout) + self.add_image = QLabel() + self.add_image.setPixmap(QPixmap(os.getcwd() + '/../images/add.png')) + # self.add_image.setObjectName('pic_label') + + self.add_text = QLabel("新建列表") + layout.addWidget(self.add_image, 3) + layout.addWidget(self.add_text, 4) + # self.set diff --git a/view/SelfListWidgetItem.py b/view/SelfListWidgetItem.py index 380a8af..4f0eff9 100644 --- a/view/SelfListWidgetItem.py +++ b/view/SelfListWidgetItem.py @@ -36,10 +36,7 @@ class SelfListWidgetItem(QListWidgetItem): self.item_name_label = QLabel(self.item_name) # print(self.item_name) self.item_name_label.setObjectName('item_name_label') - # todo - # 需要设置qss使字体靠中间一点 - # 如果有气泡使气泡靠右 - # done + # todo 需要设置qss使字体靠中间一点,如果有气泡使气泡靠右 done layout.addWidget(self.item_name_label, 3) @@ -55,4 +52,3 @@ class SelfListWidgetItem(QListWidgetItem): # 设置自定义的QListWidgetItem的sizeHint,不然无法显示 self.setSizeHint(self.widget.sizeHint()) - # 添加右键菜单 diff --git a/view/UserLabel.py b/view/UserLabel.py index 0300837..5a6e6dc 100644 --- a/view/UserLabel.py +++ b/view/UserLabel.py @@ -1,26 +1,8 @@ import os -import string -import sys -from random import randint, choice -from PyQt5.QtWidgets import * +from PyQt5.QtCore import Qt from PyQt5.QtGui import * -from utils.QSSLoader import QSSLoader -from PyQt5.QtCore import Qt, pyqtSignal - - -# def get_icon(): -# # 测试模拟图标 -# pixmap = QPixmap(16, 16) -# pixmap.fill(Qt.transparent) -# painter = QPainter() -# painter.begin(pixmap) -# painter.setFont(QFont('Webdings', 11)) -# painter.setPen(Qt.GlobalColor(randint(4, 18))) -# painter.drawText(0, 0, 16, 16, Qt.AlignCenter, -# choice(string.ascii_letters)) -# painter.end() -# return QIcon(pixmap) +from PyQt5.QtWidgets import * def about_qt(): @@ -36,12 +18,9 @@ class User(QLabel): super(User, self).__init__() self.widget = QWidget(self) self.widget.setMaximumWidth(300) - # self.resize(200, 60) self.setObjectName('User') - # todo - # 修改布局使适合微软todo的样式 - # 设置点击事件,使用右键菜单的样式添加设置、同步、退出 - # 暂时就这样 + # todo:修改布局使适合微软todo的样式,设置点击事件,使用右键菜单的样式添加设置、同步、退出,暂时就这样 + layout = QHBoxLayout() info_layout = QVBoxLayout() self.pic_label = QLabel('') @@ -50,23 +29,22 @@ class User(QLabel): QPixmap(os.path.abspath('../') + '/images/user.svg').scaled(50, 50, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)) layout.addWidget(self.pic_label, 2) - # layout.addStretch(2) self.user_name = QLabel("用户登录") self.user_name.setObjectName('user_name') self.user_mail = QLabel('794508986@qq.com') self.user_mail.setObjectName('user_mail') self.user_mail.setStyleSheet('font-size:16px') - self.menu_label = QLabel('') - self.menu_label.setObjectName('menu') - self.menu_label.setPixmap( - QPixmap(os.path.abspath('../') + '/images/up-down.svg').scaled(20, 20, Qt.IgnoreAspectRatio, - Qt.SmoothTransformation)) + # self.menu_label = QLabel('') + # self.menu_label.setObjectName('menu') + # self.menu_label.setPixmap( + # QPixmap(os.path.abspath('../') + '/images/up-down.svg').scaled(20, 20, Qt.IgnoreAspectRatio, + # Qt.SmoothTransformation)) info_layout.addWidget(self.user_name) info_layout.addWidget(self.user_mail) layout.addLayout(info_layout, 4) layout.addStretch(1) - layout.addWidget(self.menu_label, 1) + # layout.addWidget(self.menu_label, 1) self.widget.setLayout(layout) # 设置右键菜单 @@ -94,10 +72,10 @@ class User(QLabel): self.context_menu.addAction(QIcon(os.getcwd() + '/../images/setting.svg'), '设置', self.setting) self.context_menu.addAction(QIcon(os.getcwd() + '/../images/sync.svg'), '同步', self.sync) - self.context_menu.addAction(QIcon(os.getcwd() + '/../images/sync.svg'), '退出', self.exit_account) + self.context_menu.addAction(QIcon(os.getcwd() + '/../images/exit.svg'), '退出', self.exit_account) + + # todo 设置右键点击事件 - # todo - # 设置右键点击事件 def setting(self): pass @@ -108,13 +86,4 @@ class User(QLabel): pass -# if __name__ == "__main__": -# app = QApplication(sys.argv) -# main = User() -# style_sheet = QSSLoader.read_qss_file('../resource/current.qss') -# main.setStyleSheet(style_sheet) -# # print(os.path.abspath('../')) -# -# app.setWindowIcon(QIcon(os.path.abspath('../') + '/images/todo.svg')) -# main.show() -# sys.exit(app.exec_()) +