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. How can I achieve 26 touch points
Forum Update on Monday, May 27th 2025

How can I achieve 26 touch points

Scheduled Pinned Locked Moved QML and Qt Quick
qml + jsqmlqt quickqtquickdrag problem
2 Posts 2 Posters 426 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.
  • P Offline
    P Offline
    pennyboya
    wrote on 14 Feb 2022, 19:12 last edited by pennyboya
    #1

    How can I modify my code such that I have 26 touch points instead of 17 while keeping the format: A • D • G • J • M • P • S • V • Z. The • is supposed to represent the missing letters(indices). For example, If I was to click or drag between A • D. My expected results should either output B 1 or C 2.

    Currently, if you run the code as is, clicking or dragging between A • D, depending on the placement of your mouse index the output would be A 0 or D 1.

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQml 2.15
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Rectangle {
            id: root
            visible: true
    
            property string letters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    
              function newLetters(index) {
    
                  if(index % 2 === 0){
                      if(index === 16)
                          return root.letters[25]
                      else
                        return root.letters[index/2 * 3]
                  }
                  else
                      return "•"
    
              }
    
            Repeater {
                model: 17
                Text {
                    property double angle: 1.08 *  (index + 2) * Math.PI / 21 - Math.PI/2
                    x: 515 + 90 * Math.cos(angle)
                    y: 205 + 150 * Math.sin(angle)
                    text: root.newLetters(index)
                    objectName: root.newLetters(index)
                    property int idx: index
                }
            }
        }
    
        MouseArea {
            id: mouseArea
    
            anchors.fill: parent
            onPressed: processTap(Qt.point(mouse.x, mouse.y))
            onPositionChanged: processTap(Qt.point(mouse.x, mouse.y))
    
            function processTap(pos) {
                var closestActiveLetter;
                var closestDistance = Infinity;
                var closestIdx = -1;
                for(var i = 0; i < root.children.length; i++) {
                    var item = root.children[i];
                    if(!item.objectName || item.objectName === "•") {
                        continue;
                    }
                    pos = mapToItem(root, pos)
                    var disx = pos.x - item.x
                    var disy = pos.y - item.y
                    var distance = Math.sqrt(disx * disx + disy *  disy );
                    if(distance < closestDistance) {
                        closestDistance = distance;
                        closestActiveLetter = item.objectName;
                        closestIdx = item.idx;
                    }
                }
                if(closestActiveLetter) {
                    console.log(closestActiveLetter, closestIdx);
                }
    
    
            }
        }
    }
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 17 Feb 2022, 07:24 last edited by
      #2

      Hi,

      Might be a silly idea (and I currently don't know the performance hit for that one) but why not have one mouse area per Text object ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      1/2

      14 Feb 2022, 19:12

      • Login

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