Also, the reason its not working right now in your code is because you are using a QMenu. The default flags and usage for a QMenu are to be a popup type which is designed to hide when it loses focus. You are calling its exec method which will force it to act like a popup . You would want to just use a normal QWidget that is set up how you want, and show() it. I have a tool exactly like this which mimics OSX's Spotlight. The list is just a custom widget that I show underneath.
On May 7, 2012, at 7:25 AM, Justin Israel <[email protected]> wrote: > Hey Manuel, > Have you tried using a QCompleter? You realize its provided to do this exact > functionality? > http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qcompleter.html > > There are a couple different modes it can be set to, one of which being a > popup that narrows down the list as you type. > > > > On May 6, 2012, at 5:45 PM, Manuel Macha <[email protected]> wrote: > >> Hi, >> >> I'm trying to create a variation of QLineEdit where as soon as the user >> types something, a list of items that match the entered text pop up below >> the textfield. If you're not sure what I mean - it's supposed to work like >> the searchbox in any modern browser where suggestions are being displayed >> while typing. >> The problem that I'm having is that as soon as I'm displaying the menu, the >> lineedit is loosing focus which makes it impossible to type more than a >> character at a time - not exactly very user-friendly. I tried several things >> using setFocusPolicy and setFocusReason but I'm not sure if I properly >> understood how to utilize those functions. >> Could someone please have a look at the sample code below. Very much >> appreciated! >> >> http://pastebin.com/m318MY2G >> >> from PyQt4.QtGui import QLineEdit, QMenu, QAction >> >> class SearchField(QLineEdit): >> def __init__(self, parent = None): >> QLineEdit.__init__(self, parent = parent) >> self.textEdited.connect(self.popupMenu) >> >> >> def popupMenu(self): >> aMenu = QMenu() >> aMenu.addAction('Some text') >> aMenu.addAction('More text') >> globalPos = self.mapToGlobal(self.pos()) >> globalPos.setY(globalPos.y() + self.height()) >> aMenu.exec_(globalPos) >> self.setFocus() >> >> if __name__ == '__main__': >> import sys >> from PyQt4.QtGui import QApplication, QMainWindow >> app = QApplication(sys.argv) >> win = QMainWindow() >> win.setGeometry(200, 200, 128,32) >> win.setCentralWidget(SearchField()) >> win.show() >> -- >> view archives: http://groups.google.com/group/python_inside_maya >> change your subscription settings: >> http://groups.google.com/group/python_inside_maya/subscribe -- view archives: http://groups.google.com/group/python_inside_maya change your subscription settings: http://groups.google.com/group/python_inside_maya/subscribe
