Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to get mouse position when handling SplitView
Qt 6.12 LTS is out! See what's new in the release blog

How to get mouse position when handling SplitView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 471 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.
  • F Offline
    F Offline
    fromis_9
    wrote on last edited by
    #1

    Hi. I'm using QtQuick2 SplitView for my application.
    I need the mouse position when users click handle inside of the splitview.
    I included MouseArea inside of the SplitView for that, but it didn't work.
    How can I do it?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fromis_9
      wrote on last edited by fromis_9
      #2

      I make my own split view for my purpose.

      import QtQuick 2
      import QtQuick.Layouts
      
      Item {
        id: splitView
        RowLayout { anchors.fill: parent
          spacing: 0
          Rectangle { Layout.fillWidth: true; Layout.fillHeight: true
            id: leftItem
            color: "red"
          }
          ToolSeparator { Layout.fillHeight: true
            id: handle
            property int leftLimit: 0
            property int rightLimit: splitView.width
            MouseArea { anchors.fill: parent
              id: handleMouseArea
              acceptedButtons: Qt.LeftButton
              cursorShape: Qt.SplitHCursor
              onMouseXChanged: {
                /* Mouse position in the SplitView*/
                var pos = mapToItem(splitView, mouse.x, mouse.y)
                if (pressed) {
                  var xPos = pos.x - handle.width / 2
                  if (handle.leftLimit < xPos && xPos + handle.width < handle.rightLimit) {
                    /* This is basic functionality of SplitView */
                    handle.x = xPos
                    leftItem.width = handle.x
                    rightItem.x = handle.x + handle.width
                    rightItem.width = splitView.width - leftItem.width - handle.width
                  }
                }
              }
            }
          }
          Rectangle { Layout.fillWidth: true; Layout.fillHeight: true
            id: rightItem
            color: "blue"
          }
        }
      }
      

      any better?

      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
      • Unsolved