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

Reply via email to