July 20, 2012

nethanjavier nethanjavier
Lab Rat
4 posts

QTextEdit with Enter in searching

 

Hi,

I’m a newbie here. I just wanna ask about QTextEdit. I want that when I enter a integer in my qtextedit widget, it will search from a database and it will pass the the value to a QTreeWidget if it has that value from database without using the enter button. I hope you could help me. Please. Thank you.

Best Regards,
Nethan

6 replies

July 20, 2012

noregister noregister
Lab Rat
13 posts

add one SLOT method,and connect it to the Signal of QTextEdit.textChanged.
do your database query and so on in the SLOT.

July 20, 2012

nethanjavier nethanjavier
Lab Rat
4 posts

Hi, Thank you so much for your immediate reply. I confess, I’m really newbie here. I already have a python file connecting to my database and I just import it in my main file. But I don’t know how to query like for example, I have a table in my database that is Items. In that table, it has itemcode,description and price. What I want in my project is that my QtextEdit will query the item code in my database and when it finds the item,it will display the item to my Qtreeview. Is this possible? Please help me.

Best Regards,
Nethan

July 20, 2012

noregister noregister
Lab Rat
13 posts

You need subclass QAbstractItemModel [doc.qt.nokia.com] to provide the data model of treeview

and also you can get example of Qt SDK:
QtSDK\Examples\4.8\itemviews\simpletreemodel
QtSDK\Examples\4.8\itemviews\addressbook
l

July 20, 2012

nethanjavier nethanjavier
Lab Rat
4 posts

Hi Again,

I saw these examples but they are all built in C++. I’m currenlt using PyQt. Is there any example out there?

July 23, 2012

nethanjavier nethanjavier
Lab Rat
4 posts

Hi again,

Can you please help me on this? Please.

July 23, 2012

raaghuu raaghuu
Hobby Entomologist
115 posts

PyQt is not a part of the Qt Project anymore. The following is how it is done in PySide(Its official alternative).
The syntax and usage may vary, but the essential idea is the same in both. You can get more info on PyQt syntax somwhere in here [riverbankcomputing.com] or here [riverbankcomputing.com]

  1. #code here
  2.  
  3. self.myTextEdit.textChanged.connect(slotForQuery)
  4.  
  5. #other code here
  6.  
  7. def slotForQuery(self) :
  8.     textToQuery = self.myTextEdit.text()
  9.    
  10.     #rest of the query code here
  11.  
  12. #code here

i don’t know anything about database handling, so can’t say anything about that… But for performing something when the text changes in the text edit, this mechanism should work

P.S. you should consider using a QLineEdit instead of QTextEdit if you have to enter only one or two numbers in it(the code above works for it too)

 
  ‹‹ [Solved] QTreeWidget and checking if it’s vertical scroll bar is visible      QString global variable and coding problem ››

You must log in to post a reply. Not a member yet? Register here!