代码拉取完成,页面将自动刷新
from PyQt5.QtWidgets import QWidget,QLineEdit,QToolButton,QHBoxLayout
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtCore
from PyQt5.QtCore import QPoint
from PyQt5.QtGui import QPaintEvent,QMouseEvent,QPainter,QPolygon,QColor,QPen,QLinearGradient,QGradient,QFont
import FormWidgetimage
class SearchLineEdit(QLineEdit):
signalSearchContent = QtCore.pyqtSignal(str)
def __init__(self,parent=None):
super(SearchLineEdit, self).__init__(parent)
self.initForm()
self.initConnect()
self.translator()
def initForm(self):
self.setFixedSize(260,24)
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.tbnSearch = QToolButton(self)
self.tbnSearch.setFixedSize(25,24)
self.tbnSearch.setAutoRaise(True)
self.tbnSearch.setCursor(QtCore.Qt.PointingHandCursor)
self.tbnSearch.setStyleSheet("QToolButton{border-image:url(:/image/search_dark.png);"
"background:transparent;}")
mainLayout = QHBoxLayout()
mainLayout.addStretch()
mainLayout.addWidget(self.tbnSearch)
self.setTextMargins(0,0,20,0)
self.setContentsMargins(0,0,0,0)
mainLayout.setContentsMargins(2,2,4,0)
self.setLayout(mainLayout)
self.setStyleSheet("height:24px;border:1px ;border-radius:6px;"
"background-color:#E1DDDD");
def initConnect(self):
self.tbnSearch.clicked.connect(self.slotSendSearchContent)
self.returnPressed.connect(self.slotSendSearchContent)
def translator(self):
self.setPlaceholderText("请输入要查找的内容")
self.setToolTip("查找内容")
self.tbnSearch.setToolTip("查找")
def focusInEvent(self, e: QtGui.QFocusEvent):
super(SearchLineEdit, self).focusInEvent(e)
self.clear()
self.setPlaceholderText("")
self.setStyleSheet("height:24px;border:1px ;border-radius:6px;"
"background-color:#CCC000");
self.tbnSearch.setStyleSheet("QToolButton{border-image:url(:/image/search_dark.png);"
"background:transparent;}");
def focusOutEvent(self, e: QtGui.QFocusEvent):
super(SearchLineEdit, self).focusOutEvent(e)
self.setPlaceholderText("请输入要查找的内容");
self.setStyleSheet("height:24px;border:1px ;border-radius:6px;"
"background-color:#CCC7C7");
self.tbnSearch.setStyleSheet("QToolButton{border-image:url(:/image/search_dark.png);"
"background:transparent;}");
def slotSendSearchContent(self):
str = ""
if self.text() == "":
str = self.placeholderText()
else:
str = self.text()
self.signalSearchContent.emit(str)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。