Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Model View for a list and table

Model View for a list and table

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 918 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • kahlenbergK Offline
    kahlenbergK Offline
    kahlenberg
    wrote on last edited by kahlenberg
    #1

    Hi,

    I am quite new to thema model-view and I want to use it in my project. I have a list, consisting of name, page, address, value columns (all strings). I want to show them in a table and I want to add write protect (checkbox), write value (string) columns in the table but not in data model. Further, I want to collect rows that write value columns has changed.
    All example projects are only for string tables or very basic things and I could not go further with those examples. Maybe my requirement is a little bit compilcated but how can I do that?

    Thanks.

    JonBJ 1 Reply Last reply
    0
    • kahlenbergK kahlenberg

      Hi,

      I am quite new to thema model-view and I want to use it in my project. I have a list, consisting of name, page, address, value columns (all strings). I want to show them in a table and I want to add write protect (checkbox), write value (string) columns in the table but not in data model. Further, I want to collect rows that write value columns has changed.
      All example projects are only for string tables or very basic things and I could not go further with those examples. Maybe my requirement is a little bit compilcated but how can I do that?

      Thanks.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @kahlenberg
      Let's start with: are your data strings already in memory (or perhaps a text file), or are these rows & columns in an actual database?

      1 Reply Last reply
      0
      • kahlenbergK Offline
        kahlenbergK Offline
        kahlenberg
        wrote on last edited by
        #3

        Ok,
        Data is read from a text file as string and stored in a QVector (QVector<QStringList> *registers;). One row has 3 columns (name, page, address) as StringList.

        JonBJ 1 Reply Last reply
        0
        • kahlenbergK kahlenberg

          Ok,
          Data is read from a text file as string and stored in a QVector (QVector<QStringList> *registers;). One row has 3 columns (name, page, address) as StringList.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @kahlenberg
          So as your starting point I would think you want http://doc.qt.io/qt-5/qstandarditemmodel.html for your model and http://doc.qt.io/qt-5/qtreeview.html for your view, or use http://doc.qt.io/qt-5/qtreewidget.html and accept its inbuilt model.

          I would get that working before you come to add extra columns. In that light you may need the extra flexibility of QStandardItemModel + QTreeView rather than the initially-simpler QTreeWidget.

          IIRC, Qt is not that happy with attempts to have columns in the view which are not in the model. I was advised to use a third-party library when I originally asked about this (https://forum.qt.io/topic/83616/using-qsqlquerymodel-instead-of-qstandarditemmodel/3), but I haven't gotten around to implementing.

          1 Reply Last reply
          0
          • kahlenbergK Offline
            kahlenbergK Offline
            kahlenberg
            wrote on last edited by
            #5

            OK Thanks.
            Why shall I use QTreeView instead of QTableView?
            By the way, model is not restricted to have only three columns. I cad add also more columns with different datatype to model. For example I can make a struct and a QList for data:

            struct s_Register {
                        QString name;
                        quint16 page;
                        quint16 address;
                        quint32 currentValue;
                        bool writeProtect;
                        quint32 writeValue;
            };
            

            With this struct we can generate a list: QList<s_Register> *Registers; and use it as data.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved