PyQt4: data binding?

Transition from the .NET world to Python and PyQt4. I wonder if anyone is familiar with any functionality that would allow me to bind data to Qt widgets? For example (using sqlalchemy for data):

gems = session.query(Gem).all()
list = QListWidget()
list.datasource = gems

Is it possible?

+3
source share
2 answers

One option has a function that returns a list object (or tuple) from the query, and then uses it to update the QListWidget. Remember that QListWidget stores QListStrings. The update function may look like this:

def updateQListWidget(qlistwidget, values):
        """ Updates a QListWidget object with a list of values
        ARGS:
            qlistwidget  - QListWidget object
            values       - list of values to add to list widget
        """
        qlistwidget.clear()
        qlist = QtCore.QStringList()
        for v in values:
            s = QtCore.QString(v)
            qlist.append(s)
        qlistwidget.addItems(qlist) 
+3
source

Although this is not a direct replacement, you might find it useful to look at the QDataWidgetMapper class:

http://pyqt.sourceforge.net/Docs/PyQt4/qdatawidgetmapper.html

++, :

https://doc.qt.io/qt-4.8/qt-sql-sqlwidgetmapper-example.html

, mapper Qt Model/View. SQL.

+4

Source: https://habr.com/ru/post/1703924/


All Articles