Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to add item to qml listview ? the model can't change !

How to add item to qml listview ? the model can't change !

Scheduled Pinned Locked Moved QML and Qt Quick
11 Posts 2 Posters 3.9k Views 1 Watching
  • 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.
  • W Offline
    W Offline
    wshn14
    wrote on last edited by
    #1

    Hi:
    I am using qml now to develop a message app,I can get a message list model from certain lib ,the model can't change . Each message item in the model contains a time information ,a text ,a direction (in or out ), I use a listview to show it by assign the model to listview ,I make a delegate to show it .
    show like this :
    text 1
    10:10:06

    text 2
    10:10:17

    text 3
    10:12:59

    text 4
    15:22:23

    text 5
    17:35:08

    But now I want to show time once for time close messages:
    like below:

    10:10:06

    text 1

    text 2

    text 3

    15:22:23

    text 4

    15:35:08

    text 5

    message 1 2 3 are considered to be a conversation,because they talk in 1 hour ,so show 10:10:06 once at begin of message 1.

    The problem is how to make the listview show like this ?
    Thanks !!

    1 Reply Last reply
    0
    • W Offline
      W Offline
      wshn14
      wrote on last edited by
      #2

      very emergency

      1 Reply Last reply
      0
      • p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by
        #3

        Hi,

        Have a look at this "example":http://qt-project.org/doc/qt-4.8/declarative-modelviews-listview-sections.html

        157

        1 Reply Last reply
        0
        • W Offline
          W Offline
          wshn14
          wrote on last edited by
          #4

          I know you mean use the section property ,but my list item may like this

             ListElement { text: "message 1"; time: "10:15:34" }
             ListElement { text: "message 2"; time: "10:15:56" }
             ListElement { text: "message 3"; time: "10:17:06" }
             ListElement { text: "message 4"; time: "13:34:12" }
             ListElement { text: "message 5"; time: "17:45:01" }
          

          I want to make message time in one hour into one section ,thus message 1 2 3 in one section named 10:15:34 ,message 4 in one section named 13:34:12,message 5 in one section named 17:45:01 .How to implement it?

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            Ok, i think then you need to implement something like treeview as the text messages are actually the childs of time and whenever you get a new entry for time you will first need to check if it is present in the view, if not then add it and then add the text message as per the time by parsing the tree.

            157

            1 Reply Last reply
            0
            • W Offline
              W Offline
              wshn14
              wrote on last edited by
              #6

              I don't how to subclass the qml listview ,is the qml listview the same with qt c++ listview
              [quote author="p3c0" date="1382002504"]Ok, i think then you need to implement something like treeview as the text messages are actually the childs of time and whenever you get a new entry for time you will first need to check if it is present in the view, if not then add it and then add the text message as per the time by parsing the tree.[/quote]

              1 Reply Last reply
              0
              • p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by
                #7

                No what i'm trying to say is your view needs to be like a TreeView where the childs are grouped according to its repective parent.
                Here Parent being the Time and Child being the Text.
                But unfortunately Qt 5.1 or Qt 5.1 does not have TreeView yet.

                157

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  wshn14
                  wrote on last edited by
                  #8

                  Is qml have any class that I can put item in have a vertical slide capacity
                  [quote author="p3c0" date="1382004958"]No what i'm trying to say is your view needs to be like a TreeView where the childs are grouped according to its repective parent.
                  Here Parent being the Time and Child being the Text.
                  But unfortunately Qt 5.1 or Qt 5.1 does not have TreeView yet. [/quote]

                  1 Reply Last reply
                  0
                  • p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on last edited by
                    #9

                    Hi,

                    May be this "TreeView":http://qt-project.org/forums/viewthread/30521/ would help you. As according to "this":http://qt-project.org/forums/viewthread/33594/#146846 thread a TreeView can be achieved like this as of now. For vertical slide he has used ScrollView. I have not tried the code myself though.

                    157

                    1 Reply Last reply
                    0
                    • W Offline
                      W Offline
                      wshn14
                      wrote on last edited by
                      #10

                      I can't find treeview in qml ,you mean c++?
                      [quote author="p3c0" date="1382007121"]Hi,

                      May be this "TreeView":http://qt-project.org/forums/viewthread/30521/ would help you. As according to "this":http://qt-project.org/forums/viewthread/33594/#146846 thread a TreeView can be achieved like this as of now. For vertical slide he has used ScrollView. I have not tried the code myself though. [/quote]

                      1 Reply Last reply
                      0
                      • p3c0P Offline
                        p3c0P Offline
                        p3c0
                        Moderators
                        wrote on last edited by
                        #11

                        There's no TreeView in QML currently but there's a "workaround":http://qt-project.org/forums/viewthread/30521/#146845 for it. Did you see those links ?

                        157

                        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