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 put a long string to ListElement?
Forum Updated to NodeBB v4.3 + New Features

How to put a long string to ListElement?

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 4 Posters 3.5k 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.
  • O Offline
    O Offline
    owenzhao
    wrote on last edited by
    #1

    I have to use a long string to ListElements, such as
    @ListElement {
    myColor: "red"
    myText: "This is a very long paragaph This is a very long paragaphThis is a very long paragaphThis is a very long paragaphThis is a very long paragaphThis is a very long paragaphThis is a very long paragaph"
    }@
    Firstly I think I could use something like
    @ListElement {
    myColor: "red"
    myText: "This is a very long paragaph This is a very long paragaph"
    +"This is a very long paragaphThis is a very long paragaph"
    +" This is a very long paragaphThis is a very long paragaph"
    +"This is a very long paragaph"
    }@

    But The ListElement can not recongnize the + parts. only knows the first line.

    Then I try do
    @Rectangle {
    id:myRect
    property string longText: "This is a very long paragaph This is a very long paragaph"
    +"This is a very long paragaphThis is a very long paragaph"
    +" This is a very long paragaphThis is a very long paragaph"
    +"This is a very long paragaph"
    ListModel {
    ListElement {
    myColor: "red"
    myText: myRect.longText
    }
    }
    }@

    And I find ListElement don't allow properties in there data.

    Is there a special technique to write a long String in multi-lines, or I have to use a javascript variable?

    Thank you.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      billouparis
      wrote on last edited by
      #2

      I am not sure I understand your issue, but did you try this:

      @Rectangle {
      id:myRect

      ListModel {
      ListElement {
      myColor: "red"
      myText: "This is a very long paragaph This is a very long paragaph
      This is a very long paragaphThis is a very long paragaph
      This is a very long paragaphThis is a very long paragaph
      This is a very long paragaph"
      }
      }
      }
      @

      Regards,
      Bill

      1 Reply Last reply
      0
      • O Offline
        O Offline
        owenzhao
        wrote on last edited by
        #3

        Thank you for you post. However, the spaces are still recognized. But it is much better than before.
        The code below show what I want.
        @ Rectangle {
        id:myRect

         ListModel {
          ListElement {
           myColor: "red"
           myText: "This is a very long paragaph This is a very long paragaph \
        

        This is a very long paragaphThis is a very long paragaph
        This is a very long paragaphThis is a very long paragaph
        This is a very long paragaph"
        }
        }
        }
        @

        However, this is ugly when looks at the codes. Any more ideas?

        [quote author="billouparis" date="1328882605"]I am not sure I understand your issue, but did you try this:

        @Rectangle {
        id:myRect

        ListModel {
        ListElement {
        myColor: "red"
        myText: "This is a very long paragaph This is a very long paragaph
        This is a very long paragaphThis is a very long paragaph
        This is a very long paragaphThis is a very long paragaph
        This is a very long paragaph"
        }
        }
        }
        @

        Regards,
        Bill
        [/quote]

        1 Reply Last reply
        0
        • B Offline
          B Offline
          billouparis
          wrote on last edited by
          #4

          Why don't you create your list model in C++?

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vabo
            wrote on last edited by
            #5

            Hi,

            If we substitute the ListElement myText with the property longText we get the error “ListElement: cannot use script for property value”. Indeed, the property needs a processing that is not allowed. According to "documentation":http://qt-project.org/doc/qt-4.8/qml-listelement.html “Values must be simple constants; either strings (quoted and optionally within a call to QT_TR_NOOP), boolean values (true, false), numbers, or enumeration values (such as AlignText.AlignHCenter). “.
            We can use JavaScript arrays for multiline text. See for example "here":http://qt-project.org/wiki/QML_Multi-line_Texts_Handling.

            Regards

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dajansen
              wrote on last edited by
              #6

              Here's a possible solution.

              @Rectangle {
              id: myrect
              width: 360
              height: 360
              ListView { anchors.fill: parent; model: mymodel;
              delegate: Rectangle {
              height: 100
              width: 360
              Text {
              anchors.centerIn: parent; text: model.myText; width: parent.width
              wrapMode: Text.WordWrap
              }
              }
              }
              ListModel {
              id: mymodel
              }
              Component.onCompleted: {

              mymodel.append({"myColor":"red", "myText":
                  "This is a very long paragaph This is a very long paragaph"
                  +"This is a very long paragaphThis is a very long paragaph"
                  +" This is a very long paragaphThis is a very long paragaph"
                  +"This is a very long paragaph"});
              }
              

              }@

              QtQuick Quality Engineer / Lab Monkey
              Nokia Brisbane

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vabo
                wrote on last edited by
                #7

                Very good:). Now the long text is separated in a script block.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dajansen
                  wrote on last edited by
                  #8

                  [quote author="vabo" date="1331546583"]Very good:). Now the long text is separated in a script block.[/quote]

                  I'm not sure if this is appreciation or sarcasm.

                  QtQuick Quality Engineer / Lab Monkey
                  Nokia Brisbane

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    vabo
                    wrote on last edited by
                    #9

                    Of course admiration! You have added new aspects to the topic.
                    Regards

                    1 Reply Last reply
                    0
                    • O Offline
                      O Offline
                      owenzhao
                      wrote on last edited by
                      #10

                      Thank you all for the posts.
                      I currently use a tricky method that I create a empty listelement part and adding the real part in javascript.

                      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