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. Dynamic addition of component inside a grid (by click Button) and swap elements capability
Forum Updated to NodeBB v4.3 + New Features

Dynamic addition of component inside a grid (by click Button) and swap elements capability

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 234 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.
  • J Offline
    J Offline
    JorisC
    wrote on 18 Oct 2021, 11:20 last edited by JorisC
    #1

    Dear Qt/QML community

    In my app I have a button when I click it it creates an existing component (defined in zone.qml file).
    I would like to add this new component into a grid zone. The Final goal is when user drags "zone" element inside the grid he can swap position in order to reorganize itself the elements position

    Zone.qml:

    //zone.qml
    
    Item{
        id: zone
    
        MouseArea{
            ... //(I make it draggable)
        }
        Rectangle{
            width: parent.width
            height: parent.height
            anchors.fill: parent.fill
    
            ChartView{
                 ...
            }
           ListView{
               ...
            }
        }
    }
    

    I my main.qml I tried with a GridLayout. It works for my grid display objective ! (here below the code for whose are interested:

      //  Button{
      //      width: 200
      //      height: 50
      //      text:"Click Me"
      //      y:400
      //      x:2350
       //     onClicked: {
       //         Qt.createComponent("Zone.qml").createObject(splitView, {"width":scrollView.largeur/2,"height":scrollView.height/2.5});
       //     }
     //   }
    
        //    ScrollView{
        //        property alias largeur:scrollView.width
        //        property int largeur:scrollView.height
        //        id:scrollView
        //        width: Screen.width
        //        height: 0.75*Screen.height
        //        anchors.left: parent.left
        //        anchors.top: parent.top
        //        anchors.leftMargin: 0.05*parent.width
        //        anchors.topMargin: 0.05*parent.height
        //        clip: true
    
        //        GridLayout{
        //            id: splitView
        //            width: parent.width
        //            height:parent.heigh
        //            columns: 2
        //            rows:1
        //            clip: true
        //        }
    
        //    }
    

    But I didn't manage to swap position. It's ok to drag element inside the grid (as they have a mouse Area which allow drag) but the drag is free and doesn't fit with a gridposition and I don't know how to implement a drag mechanism.
    On another side, I wonder if gridView could be more adapted for that but my actual problem is that with gridView I can't add element in a grid organization ...

    Here my code with gridview attempt:

    Button{
            width: 200
            height: 50
            text:"Click Me"
            y:400
            x:2350
            onClicked: {
                //var object= Qt.createComponent("Zone.qml").createObject(parent, {"x":500,"y":500,"width":200,"height":200, "id_zone":1});
                gridmodel.append(object));
            }
        }
    
    GridView{
            x:100
            y:100
            id:gridView
            width:0.5*Screen.width
            height:Screen.height
            cellWidth: 0.5*width
            cellHeight: 0.5*height
            layoutDirection: Qt.LeftToRight
            model:ListModel{
                id:gridmodel
            }
            delegate: Grid{
                width: parent.width
                height: parent.height
                columns: 3
    
            }
    

    It doesn't work ...
    Can someone help me please, I spend a lot of time on it and I guess there is (are) some thing(s) I miss !
    Thanks a lots in advance

    Jo

    1 Reply Last reply
    0

    1/1

    18 Oct 2021, 11:20

    • Login

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