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. How to display and change two values from a single item in QListView
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 419 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.
  • M Offline
    M Offline
    myShrimp
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • M Offline
        M Offline
        myShrimp
        wrote on last edited by
        #3

        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.

        JonBJ 1 Reply Last reply
        0
        • M myShrimp

          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.

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

          @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
          2

          • Login

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