[PySide] search widget
Frank Rueter | OHUfx
frank at ohufx.com
Fri Jun 8 01:59:26 CEST 2012
Brilliant, just what I was after.
Thanks Sebastian!
On 7/06/12 8:45 PM, Sebastian Elner wrote:
> This is the search line edit class I use. The only thing to do is pass
> the SearchLineEdit two valid pixmaps for the icons. I use the icons from
> the tango desktop project. Notice that you can easily make the magnifier
> icon a button with a menu, to have the user select the "search engine"
> (uncomment the lines below). Tested with PyQt only.
>
> from PySide import QtCore, QtGui
>
> class SearchLineEdit(QtGui.QLineEdit):
>
> def __init__(self, searchPixmap, clearPixmap, parent = None):
> QtGui.QLineEdit.__init__(self, parent)
>
> self.clearButton = QtGui.QToolButton(self)
> self.clearButton.setIcon(QtGui.QIcon(clearPixmap))
> self.clearButton.setIconSize(clearPixmap.size())
> self.clearButton.setCursor(QtCore.Qt.ArrowCursor)
> self.clearButton.setStyleSheet("QToolButton { border: none;
> padding: 0px; }")
> self.clearButton.hide()
> self.clearButton.clicked.connect(self.clear)
> self.textChanged.connect(self.updateCloseButton)
>
>
> self.searchButton = QtGui.QToolButton(self)
> self.searchButton.setIcon(QtGui.QIcon(searchPixmap))
> self.searchButton.setIconSize(searchPixmap.size())
> self.searchButton.setStyleSheet("QToolButton { border: none;
> padding: 0px; }")
>
> frameWidth =
> self.style().pixelMetric(QtGui.QStyle.PM_DefaultFrameWidth)
> self.setStyleSheet("QLineEdit { padding-left: %spx;
> padding-right: %spx; } " % (self.searchButton.sizeHint().width() +
> frameWidth + 1, self.clearButton.sizeHint().width() + frameWidth + 1))
> msz = self.minimumSizeHint()
> self.setMinimumSize(max(msz.width(),
> self.searchButton.sizeHint().width() +
> self.clearButton.sizeHint().width() + frameWidth * 2 + 2),
> max(msz.height(),
> self.clearButton.sizeHint().height() + frameWidth * 2 + 2))
>
> # self.searchMenu = QtGui.QMenu(self.searchButton)
> # self.searchButton.setMenu(self.searchMenu)
> # self.searchMenu.addAction("Google")
> # self.searchButton.setPopupMode(QtGui.QToolButton.InstantPopup)
>
>
> def resizeEvent(self, event):
> sz = self.clearButton.sizeHint()
> frameWidth =
> self.style().pixelMetric(QtGui.QStyle.PM_DefaultFrameWidth)
> self.clearButton.move(self.rect().right() - frameWidth -
> sz.width(),
> (self.rect().bottom() + 1 - sz.height()) / 2)
> self.searchButton.move(self.rect().left() + 1,
> (self.rect().bottom() + 1 - sz.height()) / 2)
>
> def updateCloseButton(self, text):
> if text:
> self.clearButton.setVisible(True)
> else:
> self.clearButton.setVisible(False)
>
>
> app = QtGui.QApplication([])
> w = SearchLineEdit(QtGui.QPixmap(r"system-search.png"),
> QtGui.QPixmap(r"process-stop.png"))
> w.show()
> app.exec_()
>
>
> On 06/07/2012 06:42 AM, Frank Rueter | OHUfx wrote:
>> Hi all,
>>
>> quick question for the more experienced:
>> Is there a core widget for text search? I'm after pretty something that
>> looks pretty much like this one (at the top):
>> http://farm5.static.flickr.com/4042/4574583703_f7be03c653.jpg
>>
>> What I like is it's compactness. A little icon on one side inside the
>> box to indicate what it does, and a little "clear" icon on the other
>> side to quickly clear out the search field to return everything.
>>
>> I'm happy to try and write my own but thought I'd check if I'm missing
>> the obvious.
>>
>> Cheers,
>> frank
>> _______________________________________________
>> PySide mailing list
>> PySide at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/pyside
>
More information about the PySide
mailing list