pyqt-todolist/view/AddToDoLabel.py

55 lines
1.8 KiB
Python
Raw Normal View History

2022-04-14 16:19:59 +08:00
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QPixmap
2022-04-14 21:22:47 +08:00
from PyQt5.QtCore import Qt, pyqtSignal
2022-04-14 16:19:59 +08:00
class AddToDoAction(QLabel):
2022-04-14 21:22:47 +08:00
# 发送创建的ToDo名字
todo_name = pyqtSignal(str)
2022-04-14 16:19:59 +08:00
def __init__(self):
super(AddToDoAction, self).__init__()
self.setObjectName('add_todo_label')
# widget = QWidget(self)
2022-04-14 21:22:47 +08:00
self.setMinimumWidth(700)
2022-04-14 16:19:59 +08:00
layout = QHBoxLayout()
# widget.setLayout(layout)
2022-04-14 21:22:47 +08:00
icon = QPixmap('../images/circle.svg').scaled(30, 30, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
self.icon_label = QLabel()
self.icon_label.setPixmap(icon)
self.icon_label.setMaximumSize(30, 30)
self.icon_label.setScaledContents(True)
# icon_label.resize(icon.width(), icon.height())
self.line_edit = QLineEdit()
# self.line_edit.setMinimumHeight(50)
# self.line_edit.clicked.connect(self.line_edit_action)
self.line_edit.setObjectName('add_line_edit')
2022-04-14 16:19:59 +08:00
self.line_edit.setPlaceholderText('添加任务')
2022-04-14 21:22:47 +08:00
self.line_edit.returnPressed.connect(lambda: self.line_edit_add(self.line_edit.text()))
# self.line_edit.se
# self.line_edit.setEnabled(False)
# self.line_edit.
# todo : QLineEdit点击事件
# self.line_edit.setAlignment(Qt.AlignLeft)
2022-04-14 16:19:59 +08:00
2022-04-14 21:22:47 +08:00
layout.addWidget(self.icon_label, 1, Qt.AlignLeft)
layout.addWidget(self.line_edit, 6, Qt.AlignLeft)
layout.addStretch(1)
2022-04-14 16:19:59 +08:00
self.setScaledContents(True)
# self.sizeHint()
self.setLayout(layout)
2022-04-14 21:22:47 +08:00
self.show()
# def line_edit_action(self):
# print('click left button')
# todo : 回车添加事件
def line_edit_add(self, name):
self.todo_name.emit(name)
print(name)
self.line_edit.clear()
2022-04-14 16:19:59 +08:00
# widget.show()