做了一个搜索条
参考:
(4条消息) Qt 之自定义搜索框_青春不老,奋斗不止!-CSDN博客_qt搜索框
里面的第一种方法会出现图标模糊的情况,然后采用第二种方法成功解决!
这里有一个图标模糊的文章可以看一下:
Qt图标显示模糊原因及解决方法 (huyaohui.com)
self.line_edit = QLineEdit(self)
self.line_edit.setFixedHeight(self.selectheight)
self.line_edit.setAttribute(Qt.WA_InputMethodEnabled, False)#屏蔽输入法
self.line_edit.setStyleSheet(u"background-color: rgb(33, 37, 43);\
border-radius: 17px;")
self.line_edit.setPlaceholderText(QCoreApplication.translate("MainWindow", u"搜索节点..", None))
self.line_edit.returnPressed.connect(self.lineEdit_function)
self.extention = CodeAC(self.line_edit)
self.selectbutton = QPushButton("",self)
self.selectbutton.clicked.connect(self.selectNode)
self.selectbutton.setCursor(QCursor(Qt.PointingHandCursor))
self.selectbutton.setFixedSize(self.selectheight-4,self.selectheight-4)
self.selectbutton.setStyleSheet("border: none;border-radius: 15px;")
icon1 = QIcon()
icon1.addFile(u":/icons/images/icons/cil-magnifying-glass.png", QSize(), QIcon.Normal, QIcon.Off)
self.selectbutton.setIcon(icon1)
self.select_hlayout = QHBoxLayout()
self.select_hlayout.addStretch()
self.select_hlayout.addWidget(self.selectbutton)
self.select_hlayout.setSpacing(0)
self.select_hlayout.setContentsMargins(0, 0, 2, 0)
self.line_edit.setLayout(self.select_hlayout)
#icon1 = QIcon()
#icon1.addFile(u":/icons/images/icons/cil-magnifying-glass.png", QSize(50,50), QIcon.Normal, QIcon.Off)
#new_action = QAction(self.line_edit)#创建对象
#new_action.setIcon(icon1) #设置图标
#new_action.triggered.connect(self.selectNode)#点击信号
#self.line_edit.addAction(new_action,QLineEdit.TrailingPosition)
文章中提到了QLineEdit
的icon模糊,所以弃用
QAction而是直接采用按钮的方式,这样就不会模糊了