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. Usage of Delegate
Qt 6.11 is out! See what's new in the release blog

Usage of Delegate

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 1.7k 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.
  • R Offline
    R Offline
    RG90
    wrote on last edited by
    #1

    Hi,

    I want to delegate for two components so that both can be instantiate. Is it possible to have two components in a delegate.

    Thanks

    E 1 Reply Last reply
    0
    • R RG90

      Hi,

      I want to delegate for two components so that both can be instantiate. Is it possible to have two components in a delegate.

      Thanks

      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @RG90 You can have one Item and inside it two Items. What exactly do you need, why would you need to do that?

      R 1 Reply Last reply
      0
      • E Eeli K

        @RG90 You can have one Item and inside it two Items. What exactly do you need, why would you need to do that?

        R Offline
        R Offline
        RG90
        wrote on last edited by
        #3

        @Eeli-K
        I want to make two components as dynamic object so that they can be dragged on screen simultaneously. I tried it but I could not see the change.. Do the two items need to be same components like Image.

        Marco PellinM 1 Reply Last reply
        0
        • R RG90

          @Eeli-K
          I want to make two components as dynamic object so that they can be dragged on screen simultaneously. I tried it but I could not see the change.. Do the two items need to be same components like Image.

          Marco PellinM Offline
          Marco PellinM Offline
          Marco Pellin
          wrote on last edited by
          #4

          @RG90
          As @Eeli-K said, you have to declare your composite component as an Item, which includes your sub-elements.
          Talking about dragging items on screen, you have to use the MouseArea component, which has a nice property called drag.target which gives draggable functionalities on a given element, passing its id.

          Here my example code:

          ApplicationWindow {
              visible: true
              width: 640
              height: 480
              title: qsTr("Drag me!")
          
              Item {
                  id: myCompositeItem
                  Rectangle {
                      width: 100
                      height: 100
                      color: "red"
                  }
                  Rectangle {
                      width: 100
                      height: 100
                      x: 250
                      color: "green"
                  }
              }
          
              MouseArea {
                  anchors.fill: parent
                  drag.target: myCompositeItem
              }
          }
          

          I don't know if I fully answered to your question, since you were talking about delegates.

          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