pyqt-todolist/view/SelfListWidgetItem.py

57 lines
2 KiB
Python
Raw Permalink Normal View History

import os
2022-04-01 22:25:19 +08:00
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
2022-04-23 17:36:22 +08:00
from PyQt5.QtCore import Qt, pyqtSignal
2022-04-01 22:25:19 +08:00
class SelfListWidgetItem(QListWidgetItem):
"""
:param item_name: 列表名称
:param uid: 当前列表的uuid
2022-04-01 22:25:19 +08:00
:param todo_count: 设置剩余代办数量默认为零
:param show_icon: 设置显示的图标路径默认为空
"""
2022-04-23 17:36:22 +08:00
update_action = pyqtSignal()
2022-04-01 22:25:19 +08:00
def __init__(self, item_name, todo_count=0, uid=None, show_icon=os.getcwd()+'/../images/icon/星宿.svg'):
2022-04-01 22:25:19 +08:00
super(SelfListWidgetItem, self).__init__()
layout = QHBoxLayout()
# print(show_icon)
self.item_name = item_name
self.todo_count = todo_count
self.show_icon = show_icon
# 布局
self.widget = QWidget()
self.widget.setLayout(layout)
# 添加左边的图标和右边的气泡
if self.show_icon:
self.icon_label = QLabel('')
self.icon_label.setPixmap(
QPixmap(self.show_icon).scaled(30, 30, Qt.IgnoreAspectRatio, Qt.SmoothTransformation))
layout.addWidget(self.icon_label, 1)
# 添加
self.item_name_label = QLabel(self.item_name)
# print(self.item_name)
self.item_name_label.setObjectName('item_name_label')
2022-04-01 22:25:19 +08:00
layout.addWidget(self.item_name_label, 3)
if self.todo_count:
# 打印出代办数目
print('todo_count:', self.todo_count)
2022-04-01 22:25:19 +08:00
self.todo_count_label = QLabel(str(self.todo_count))
self.todo_count_label.setFixedSize(16, 16)
2022-04-01 22:25:19 +08:00
self.todo_count_label.setScaledContents(True)
self.todo_count_label.setObjectName('todo_count_label')
self.todo_count_label.setAlignment(Qt.AlignCenter)
layout.addWidget(self.todo_count_label, 1)
# 设置自定义的QListWidgetItem的sizeHint不然无法显示
self.setSizeHint(self.widget.sizeHint())
# main=MainWidget()
def change_name(self):
pass