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. Presentation for custom data types by views
QtWS25 Last Chance

Presentation for custom data types by views

Scheduled Pinned Locked Moved Unsolved General and Desktop
qstandarditemqvariantdata modelscustom datapresentation
5 Posts 2 Posters 1.6k 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.
  • E Offline
    E Offline
    elfring
    wrote on last edited by
    #1

    I imagine that the function “setData” can be called within the implementation for a constructor of a class which was derived from QStandardItem. The provided default functionality (including support for custom data types) would be reused then.

    The available view classes provide reasonable data displays for standard data types. Additional development efforts are needed (as usual) to specify desired software behaviour for custom data types when they are finally used from the referenced data model.

    • Which member functions should be overridden for extra data processing?
    • Which programming approaches would you like to recommend here?
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      There's only 1 answer: a delegate.

      a QStyledItemDelegate subclass is what you need. If it's only about displaying the data you just need to reimplement paint() (or displayText() if it's enough for you) and sizeHint(). The other virtual methods listed in the class docs are needed to allow users to edit the data

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      E 1 Reply Last reply
      1
      • VRoninV VRonin

        There's only 1 answer: a delegate.

        a QStyledItemDelegate subclass is what you need. If it's only about displaying the data you just need to reimplement paint() (or displayText() if it's enough for you) and sizeHint(). The other virtual methods listed in the class docs are needed to allow users to edit the data

        E Offline
        E Offline
        elfring
        wrote on last edited by
        #3

        If it's only about displaying the data you just need to reimplement paint()

        • Are there any more answers (or software design constraints) to consider?
        • Can the amount of “painting” be reduced because specific standard functionality can be used if the complexity level will be determined from a custom data type?
          (It might occasionally be sufficient to concatenate a few numbers and strings from the data which is provided by a QVariant object from the model.)
        VRoninV 1 Reply Last reply
        0
        • E elfring

          If it's only about displaying the data you just need to reimplement paint()

          • Are there any more answers (or software design constraints) to consider?
          • Can the amount of “painting” be reduced because specific standard functionality can be used if the complexity level will be determined from a custom data type?
            (It might occasionally be sufficient to concatenate a few numbers and strings from the data which is provided by a QVariant object from the model.)
          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          @elfring said in Presentation for custom data types by views:

          Are there any more answers (or software design constraints) to consider?

          Not really, no. Unless you go into very specific obscure cases

          @elfring said in Presentation for custom data types by views:

          (It might occasionally be sufficient to concatenate a few numbers and strings from the data which is provided by a QVariant object from the model.

          If the data is in a single role then displayText() is what you are looking for instead of reimplementing the entire paint()

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          E 1 Reply Last reply
          1
          • VRoninV VRonin

            @elfring said in Presentation for custom data types by views:

            Are there any more answers (or software design constraints) to consider?

            Not really, no. Unless you go into very specific obscure cases

            @elfring said in Presentation for custom data types by views:

            (It might occasionally be sufficient to concatenate a few numbers and strings from the data which is provided by a QVariant object from the model.

            If the data is in a single role then displayText() is what you are looking for instead of reimplementing the entire paint()

            E Offline
            E Offline
            elfring
            wrote on last edited by
            #5

            Unless you go into very specific obscure cases

            Another software design possibility would be to fiddle with proxies for data models (and their items), wouldn't it?

            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