52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
from PyQt5.QtWidgets import *
|
||
from PyQt5.QtGui import *
|
||
from PyQt5.QtCore import Qt
|
||
import sys
|
||
import os
|
||
|
||
|
||
class SelfListWidgetItem(QListWidgetItem):
|
||
"""
|
||
:param item_name: 列表名称
|
||
:param todo_count: 设置剩余代办数量,默认为零
|
||
:param show_icon: 设置显示的图标路径,默认为空
|
||
"""
|
||
|
||
def __init__(self, item_name, todo_count=0, show_icon=None):
|
||
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)
|
||
|
||
# self.list_item = QLabel('')
|
||
|
||
# 添加左边的图标和右边的气泡
|
||
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())
|