Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Need a little help on Abstract lists views



  • Hello, i'm new on qt design, i'm used to web programming as json objects and the way data is shown in qt is a little bit different.. I need a little help.

    So, i'm working with a python program that needs to communicate with a qt frontend with qml, i have a basic understanding of listviews, models and delegates, what i dont understand is the abstract classes i need to work with on the backend.

    I want to show a list of elements that i generate querying a database that have properties and show them on the qt UI.

    For example i extract 20 fields that have for example (name: "foo", speed: "bar", lenght: "baz") on the backend and i want to wrap them on a listview and show it.

    This explanation is a little bit generalist, this is something i want to do:
    https://www.youtube.com/watch?v=6eHWnLyijow
    But instead of showing a list from a qml listview file i want to build it from a python object/dictionary.

    Greets.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Since you are using a database, you might want to first take a look at this wiki article about using Qt's QSqlQueryModel with QML to see if this approach covers what you need.


  • Banned

    From my understanding of what QSqlQueryModel does I disagree with @SGaist as that ties your database to tightly to your front-end which you seem to already understand. I work with a database on the backend and my self-contained encapsulated Database Class in pure Python handles all my interactions with the database engine and then just sends the requested results (if any) back to the Gui in the form of a Recordset like you have shown.

    That said on the frontend I use one of those Abstract Data Models to render the data into my QTreeView and I concur using them can be a bit difficult initially. If you have a MUC (or MRE) of what you are trying to do and can post it then I can probably help you with that.



  • thanks for the reply, i use database queries but the data is somewhat manipulated before beign shown, i push values, and the data is manipulated before beign shown and then i show it, i would like to know if there is a way of interacting with the UI for example:

    i have this data model in a list:

    {
    name: "foo"
    width: 1000
    height: 2000
    bottom: 500
    description: "bar baz"
    }

    i want to pass this and show a ListModel with the name and description and put the size of the element with the width and height passed, i might need to pass svgs to beign shown, what i know is that i need to use the QAbstracListModel and create my own List Model and override the methods.
    What i don't know is i have a list of this objects and i need to insert this data on my own ListModel class, and then pass it to the UI.

    I know on qt the delegate you can format how each element is beign shown, the list model have this format:

    ListModel {
    ListElement {
    name: "foo"
    }
    ListElement {
    name: "bar"
    }

    and the list view will iterate and will show all the elements i will send from the backend.

    This might seem a bad concept on how models in qt works, but that's what i understood, i just want to know how to program the abstract class and show the data on qt


  • Banned

    okay first -- I will have to check which I cannot do today -- but I have implemented a dictionary (of some sort) that I use in conjunction with Abstract Data Model for my View of the data -- try to get to that tomorrow



  • @Denni-0 i would appreciate that, my project consists of replacing a REST API to a QT GUI, before i was using html/js on front-end, now i need to use QT.
    Which means i have all the implementations methods recieving and sending json data(json is also a javascript object or a python dictionary that it's easily parsed between), now i need to translate this input/output data into QT.


  • Banned

    Yep and is there very reason you do not tie a database tightly to its front end ;-) will try to sort it out and get something up by tomorrow


Log in to reply