pyqt-todolist/view/AddToDoLabel.py
2022-04-14 21:22:47 +08:00

54 lines
1.8 KiB
Python

from PyQt5.QtWidgets import *
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import Qt, pyqtSignal
class AddToDoAction(QLabel):
# 发送创建的ToDo名字
todo_name = pyqtSignal(str)
def __init__(self):
super(AddToDoAction, self).__init__()
self.setObjectName('add_todo_label')
# widget = QWidget(self)
self.setMinimumWidth(700)
layout = QHBoxLayout()
# widget.setLayout(layout)
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')
self.line_edit.setPlaceholderText('添加任务')
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)
layout.addWidget(self.icon_label, 1, Qt.AlignLeft)
layout.addWidget(self.line_edit, 6, Qt.AlignLeft)
layout.addStretch(1)
self.setScaledContents(True)
# self.sizeHint()
self.setLayout(layout)
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()
# widget.show()