pyqt-todolist/view/SelfListWidgetItem.py

56 lines
2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import Qt, pyqtSignal
class SelfListWidgetItem(QListWidgetItem):
"""
:param item_name: 列表名称
:param uid: 当前列表的uuid
:param todo_count: 设置剩余代办数量,默认为零
:param show_icon: 设置显示的图标路径,默认为空
"""
update_action = pyqtSignal()
def __init__(self, item_name, todo_count=0, uid=None, show_icon=os.getcwd()+'/../images/icon/星宿.svg'):
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')
layout.addWidget(self.item_name_label, 3)
if self.todo_count:
# 打印出代办数目
print('todo_count:', self.todo_count)
self.todo_count_label = QLabel(str(self.todo_count))
self.todo_count_label.setFixedSize(16, 16)
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