Results 1 to 2 of 2

Thread: QML MouseArea MapToItem not position the item correctly

  1. #1
    Join Date
    May 2011
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Cool QML MouseArea MapToItem not position the item correctly

    I have a problem with QML, I need to create a Rectangle when I do a double click on MouseArea.

    The problem is that the Rectangle appears just below the mouse pointer, never in the exact position.
    Can anyone tell what's wrong and how can I solve this problem.

    Qt Code:
    1. Rectangle {
    2. id: root
    3. width: 360
    4. height: 360
    5. color: "white"
    6.  
    7. //Initial Values
    8. property int mousePosX: 0
    9. property int mousePosY: 0
    10. property bool showReservoir: false
    11.  
    12. MouseArea {
    13. id: drawArea
    14. anchors.fill: parent
    15. onDoubleClicked: {
    16. var pos = mapToItem(drawArea, mouse.x, mouse.y)
    17. drawReservoir(Math.abs(pos.x), Math.abs(pos.y))
    18. }
    19. }
    20.  
    21. Reservoir {
    22. id: m_nodeReservoir
    23. width: 60
    24. height: 60
    25. }
    26.  
    27. function drawReservoir(positionX, positionY)
    28. {
    29. m_nodeReservoir.x = positionX
    30. m_nodeReservoir.y = positionY
    31. m_nodeReservoir.visible = true
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 

    Thanks!!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QML MouseArea MapToItem not position the item correctly

    How does "just below" manifest itself?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. [SOLVED] QTableWidget can not add item correctly
    By porterneon in forum Newbie
    Replies: 0
    Last Post: 1st August 2011, 17:49
  2. Manage correctly QListView item
    By noct in forum Newbie
    Replies: 3
    Last Post: 26th November 2010, 08:34
  3. How to get item position in QTreeWidget?
    By wesley8086 in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2010, 05:28
  4. Item position in QMap?
    By lni in forum Qt Programming
    Replies: 15
    Last Post: 16th March 2009, 10:11
  5. mapToItem() question
    By Alex Brophy in forum Newbie
    Replies: 2
    Last Post: 18th April 2008, 09:55

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.