Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    关于QML中childAT(),希望得到帮助

    Chinese
    3
    5
    2812
    Loading More Posts
    • 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.
    • H
      hill last edited by

      我是一个接触QML的新手,在学习之余想做一个自娱自乐的小游戏
      在制作过程中,希望很自如的移动Rectangle中的一个Lable,想到MouseArea中的drag功能,但是,drag对于
      已经规定了anchors的Lable是不能执行drag的,于是比较纠结了。
      想通过childAt(mouseX,mouseY)自动识别鼠标点击的Lable,进而移动它。但是,实在不知道childAt到底反馈的是
      什么内容:
      举例:parent.childAt(mouseX,mouseY).anchors.leftMargin = 150;这句肯定是执行不通的,但是我希望得到我想要
      的结果,即修改鼠标所在Lable的leftMargin,该如何实现的,真谢谢了。

      1 Reply Last reply Reply Quote 0
      • L
        lingyun9833 last edited by

        可不可以通过Lable建个QRect,用contains()方法,判断鼠标是否在rect内。

        As a tree, I have my own posture.

        1 Reply Last reply Reply Quote 0
        • H
          hill last edited by

          对于几个不同的label如何进行判断?可以自动选择我鼠标点击的label

          1 Reply Last reply Reply Quote 0
          • V
            Vincent007 last edited by

            try transform instead of changing leftMargin.

            1 Reply Last reply Reply Quote 0
            • H
              hill last edited by

              已经找到答案了,就是mousearea的位置问题,要放在所有component的前面,这样通过mapToItem()和childAt()就可以实现对各个label的识别

              1 Reply Last reply Reply Quote 0
              • First post
                Last post