Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved How to display and change two values from a single item in QListView

    General and Desktop
    3
    4
    139
    Loading More Posts
    • 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.
    • M
      myShrimp last edited by

      Hey,
      I am creating a QStyledItemDelegate and need two display two values (QString and QDateTime) in a single item and need two change both in a database after editing the text displayed. Is there any way two achieve this?
      Thank you

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        You can overwrite the setModelData to do that.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • M
          myShrimp last edited by

          Thanks for your response!
          I think I expressed myself very vaguely. What I want to achieve exactly is that I want to use a QSqlQueryModel to fill a QListView with items. Each item should get a value from two columns, which should both be changed after editing in the model. I know that I can use setModelData to overwrite values from the model with those from the editor widget.

          JonB 1 Reply Last reply Reply Quote 0
          • JonB
            JonB @myShrimp last edited by

            @myShrimp
            Then kind of: what is your exact question, what answer are you looking for? There won't (I imagine) be an example of this out there, as it;s a rather unusual thing to do.

            I think your QSqlQueryModel should map one-to-one with the actual columns in the database, for simplicity. What you then do with that as you map to/from the view/styled delegate is up to you. It sounds like your requirement may be a bit messy, but presumably it can be done.

            I don't know, but it might help break it down if you interposed a QAbstractProxyModel between the SQL model and the view. Starting from a QIdentityProxyModel. You could then do your "conglomeration"/"split" of the dual columns there. Since data items can be any QVariant, I'm thinking a struct/QPair for the string-date pair. So it gets presented as one column item to/from the view, but separate columns to/from the database. If it's only a QListView and not a full QTableView maybe I'm over-engineering and you can do it directly, but it's a thought.

            1 Reply Last reply Reply Quote 2
            • First post
              Last post