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



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



  • 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



  • You need subclass "QAbstractItemModel":http://doc.qt.nokia.com/4.7-snapshot/qabstractitemmodel.html 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



  • Hi Again,

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



  • Hi again,

    Can you please help me on this? Please.



  • 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":http://www.riverbankcomputing.com/static/Docs/PyQt4/html/classes.html or "here":http://www.riverbankcomputing.com/static/Docs/PyQt4/html/index.html

    @
    #code here

    self.myTextEdit.textChanged.connect(slotForQuery)

    #other code here

    def slotForQuery(self) :
    textToQuery = self.myTextEdit.text()

    #rest of the query code here
    

    #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)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.