943,879 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 768
  • Python RSS
Aug 27th, 2008
0

Another PyQt Question (Easier this time)

Expand Post »
Ok I'll get straight to the point, how can a create a search box? You know, you type something in and it filters out the ones that don't match. Is there a special widget for this? Or would I have to create a normal lineedit widget and do all the filtering manually?
Reputation Points: 10
Solved Threads: 2
Newbie Poster
OutOfReach is offline Offline
19 posts
since Aug 2008
Aug 28th, 2008
0

Re: Another PyQt Question (Easier this time)

A Google codesearch came up with only the do it yourself, the gist of which used textChanged. This snippet was in one of the hits
Python Syntax (Toggle Plain Text)
  1. searchLabel = QtGui.QLabel(" Search", self)
  2. hLayout.addWidget(searchLabel)
  3. self.searchText = QtGui.QLineEdit()
  4. searchLabel.setBuddy(self.searchText)
  5. hLayout.addWidget(self.searchText)
  6.  
  7. self.treeWidget = self.createTreeWidget()
  8. vLayout.addWidget(self.treeWidget)
  9.  
  10. self.connect(self.searchText,
  11. QtCore.SIGNAL('textChanged(QString)'),
  12. self.treeWidget.searchItemName)
Last edited by woooee; Aug 28th, 2008 at 4:56 pm.
Reputation Points: 741
Solved Threads: 692
Nearly a Posting Maven
woooee is offline Offline
2,305 posts
since Dec 2006
Aug 28th, 2008
0

Re: Another PyQt Question (Easier this time)

Ok, so I'll have to do it manually, should be easy.
Thank you
Reputation Points: 10
Solved Threads: 2
Newbie Poster
OutOfReach is offline Offline
19 posts
since Aug 2008
Aug 28th, 2008
0

Re: Another PyQt Question (Easier this time)

Hmm well it turned out a little harder than I was expecting, I am using a QListWidget, I am trying to search for items in the list, but I have a problem, I plan on clearing the list and showing the ones that match, but If i clear the list I'll delete the existing entries, should I put them in a list, dictionary, etc...?
Reputation Points: 10
Solved Threads: 2
Newbie Poster
OutOfReach is offline Offline
19 posts
since Aug 2008
Aug 29th, 2008
0

Re: Another PyQt Question (Easier this time)

In pseudo-code it would be something like this assuming a class format (ignoring case for now)
Python Syntax (Toggle Plain Text)
  1. def __init__(self):
  2. self.orig_list=[ "Original", "words", "you", "want", "to", "test"]
  3. self.new_list = orig_list[:] ## first pass - to be used by test_list
  4.  
  5. def compare_when_text_changed():
  6. test_list=self.new_list[:]
  7. self.new_list=[]
  8. for word in test_list:
  9. if word.startswith(self.entered_in_qt_edit_box):
  10. self.new_list.append(word)
  11.  
  12. ## self.new_list now contains the words that match so far
  13. ## update list box from self.new_list
  14.  
  15. ## not necessary to return anything since self. is used.
I thought that someone would have posted code to do this, but coding this could become so funky that no one wants to put it out there on the internet I guess.
Last edited by woooee; Aug 29th, 2008 at 9:33 pm.
Reputation Points: 741
Solved Threads: 692
Nearly a Posting Maven
woooee is offline Offline
2,305 posts
since Dec 2006
Aug 30th, 2008
0

Re: Another PyQt Question (Easier this time)

Ahh! Man your a lifesaver! You just saved me from hours and hours of frustration! I cannot thank you enough!!
Reputation Points: 10
Solved Threads: 2
Newbie Poster
OutOfReach is offline Offline
19 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: help with file reading
Next Thread in Python Forum Timeline: reading in multiple arrays from a single file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC