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 keep an element at a 'fixed' position relative to another element?
QtWS25 Last Chance

How can I keep an element at a 'fixed' position relative to another element?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
layoutqml
2 Posts 2 Posters 264 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.
  • S Offline
    S Offline
    simonsanchezart
    wrote on 22 Nov 2024, 15:00 last edited by
    #1

    Hi, here's a video of what my issue is

    I want the blue dot to be in the 'hand' of the image at all times, without scaling.
    I also want to do this for any kind of element (text, button, etc...)
    How can I do this?

    My QML looks something like this

    Image {
        anchors.fill: parent
        horizontalAlignment: Image.AlignHCenter
        source: "images/UI_Assets/background.png"
        fillMode: Image.PreserveAspectCrop
        width: 800
        height: 600
    
        Image {
            id: image
            anchors.fill: parent
            source: "images/UI_Assets/background_body.png"
            fillMode: Image.PreserveAspectFit
    
            Image {
                id: dot
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.top: parent.top
                anchors.bottom: parent.bottom
                anchors.leftMargin: 455
                anchors.rightMargin: 299
                anchors.topMargin: 277
                anchors.bottomMargin: 277
                source: "images/UI_Assets/button_circle_b.png"
                fillMode: Image.PreserveAspectFit
            }
        }
    

    Thanks a lot

    1 Reply Last reply
    0
    • J Offline
      J Offline
      johngod
      wrote on 23 Nov 2024, 15:08 last edited by
      #2

      Don't use anchors for the dot, use a fixed value, something like

      Image {
      id: dot
      width: someWidth
      height: someHeight
      x: someXPositionRelativeToXBodyImage
      y: someYPositionRelativeToYBodyImage
      .....
      }

      1 Reply Last reply
      0

      1/2

      22 Nov 2024, 15:00

      • 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