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. Clickable List View elements
Forum Updated to NodeBB v4.3 + New Features

Clickable List View elements

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 2 Posters 10.1k 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.
  • M Offline
    M Offline
    Mehrotra
    wrote on last edited by
    #1

    Hello everyone!!
    Can we make the elements of ListView or for that GridView and PathView clickable to produce animation to switch to other qmls. Like say if i have 3 elements in ListView say abc def ghi then when i click on abc def and ghi swishes by to open a different QML linked to abc on clicking. If yes, then how??

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on last edited by
      #2

      Hello,

      First in your delegate element use "MouseArea":http://doc.qt.nokia.com/4.7-snapshot/qml-mousearea.html stretched to the size of delegate.

      Than onClicked implement logic to show new qml file. You can use "Loader":http://doc.qt.nokia.com/4.7-snapshot/qml-loader.html for example.

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

      • Linu...
      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mehrotra
        wrote on last edited by
        #3

        Won't that just restrict the usage of all the elements having the same QMLs being opened when clicked on.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          task_struct
          wrote on last edited by
          #4

          Delegate should know which qml file to open depending on index role for example. Or model can provide that information.

          "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

          • Linu...
          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mehrotra
            wrote on last edited by
            #5

            I'll elaborate a bit on what i a planning to do. I am supposed to create a lot of menus with different amount of options on the menus. So i created a generic QML containing the delegate and the list view and then from other QML put in the model to get the desired results. Since every menu has the same layout but there are additional features also available except on the contents of the menu this works for me. Now i am having problems linking the different QMLs of the menus.

            I tried giving another variable in the ListElement for a signal but that generates an error of cannot use script value as property.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              task_struct
              wrote on last edited by
              #6

              If all menu items are defined in static ListModel( they don't change during runtime ), you can add one more role to ListElement that contain qml file name.

              Something like this:
              @
              ListModel {
              ListElement {
              name: "Menu1"
              qmlFile: "QmlFile1.qml"
              }

              ListElement {
              name: "Menu2"
              qmlFile: "QmlFile2.qml"
              }
              .....
              }
              @

              and than in you delegate:

              @
              onClicked: { yourLoaderId.source = qmlFile }
              @

              If you want to use a function in ListModel, see "this example":http://developer.qt.nokia.com/wiki/Qt_Quick_Carousel#70b4903abcb62ace84264ad0443ae759

              "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

              • Linu...
              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mehrotra
                wrote on last edited by
                #7

                Ok i am not defining all the menus in one list model. Basically through the generic delegate and generic list view i am using the model everytime i want to make the menus. The code is to the generic delegate and list view is:

                @
                Rectangle{
                ...
                Component{
                ..
                Image{
                ..
                }
                }

                    ListView{
                          model:image_model 
                          ...
                    }
                

                }
                @

                The name of the file is Buttons.qml
                Then there is another file like HomeMenu.qml that has the following code:

                @
                Buttons{
                ...
                ListView{
                ListModel{
                id:image_model ;
                ...
                }
                }
                }
                @

                What i want is the animate the current menu out of the screen and a new window pops open according to the element clicked of the ListElement.

                And what do you mean when you say static ListModel is there a dynamic way of doing it as well??

                [EDIT: code formatting, please wrap in @-tags, Volker]

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Mehrotra
                  wrote on last edited by
                  #8

                  And thank you so much for your replies every reply is like so helpful. Thanks a lot!!

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    task_struct
                    wrote on last edited by
                    #9

                    To animate menu out of screen you can define animation in it and when menu is clicked, start animation.

                    For pop up you can use tje same approach, and start animation on
                    @Component.onCompleted:@ or something like this in your windown root item:

                    @
                    NumberAnimation on scale { from: 0; to: 1; duration: 500 }
                    @

                    To dynamicly change ListModel see it's "methods":http://doc.qt.nokia.com/4.7-snapshot/qml-listmodel.html#append-method

                    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

                    • Linu...
                    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