Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. 关于QML中childAT(),希望得到帮助
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Chinese
5 Posts 3 Posters 3.1k 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.
  • H Offline
    H Offline
    hill
    wrote on last edited by
    #1

    我是一个接触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
    0
    • L Offline
      L Offline
      lingyun9833
      wrote on last edited by
      #2

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

      As a tree, I have my own posture.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hill
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vincent007
          wrote on last edited by
          #4

          try transform instead of changing leftMargin.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hill
            wrote on last edited by
            #5

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

            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