从右到左轻弹

Right to left Flickable

当我将 child 添加到 Flickable 时,它会将其锚定在整个控件的左侧,但我希望 flickable 的 child 锚定在整个控件(我认为当 flickable 中有任何内容时,它的 flickableItem implicitWidth 会影响整个控件的宽度,这就是为什么我不能使用 anchors.right = parent.right ),Flickable 中没有 layoutDirection 属性 LayoutMirroring 在 flickable 中不起作用,我如何强制 Flickable 从其 body 的右边距绘制 child?
这是我的轻弹控件:

// ScrollableItem.qml

Flickable{
    id:root
    contentWidth: pane.implicitWidth
    contentHeight: pane.implicitHeight
    boundsBehavior: Flickable.StopAtBounds
    flickableDirection: Flickable.AutoFlickIfNeeded
    default property alias content : pane.contentItem

    Pane{
        id:pane
    }
    ScrollIndicator.vertical: ScrollIndicator{

    }
    ScrollIndicator.horizontal: ScrollIndicator{

    }
}

我是这样使用它的:

ScrollableItem{
   width : parent.width
   height : parent.height
   RowLayout{
      spacing: 500
      layoutDirection: Qt.RightToLeft
      Button{
      }
      Button{
      }
      Button{
      }
   }
}

Qml 不关心 ScrollableItemwidth : parent.width,如果我在控件中设置宽度,它不会轻弹,我也尝试在 child 中使用 anchors.right,但是没有工作。有没有办法强制 flickable child 从屏幕右侧流出?

UPDATE : 让我用图片告诉你

你看到窗格锚定在哪里了吗?将窗格锚定到右侧是不可能的,并且没有布局方向,窗格的宽度取决于 child 宽度,这是一个 rowLayout,所以如果窗格宽度低于 flickable 宽度,它将始终绘制在 flickable 的左边缘,我想在 flickable

的右边缘绘制

实际上,Flickable 在逻辑上不应该具有锚定功能。 因此,您需要通过 :

明确地将 Flickable 向右移动
// ScrollableItem.qml
Flickable{
    id:root
    contentWidth: pane.implicitWidth
    contentHeight: pane.implicitHeight
    boundsBehavior: Flickable.StopAtBounds
    flickableDirection: Flickable.AutoFlickIfNeeded
    default property alias content : pane.contentItem
    leftMargin: pane.contentWidth >= root.width ? 0 : root.width - pane.contentWidth
    contentX:  pane.mirrored ? pane.width : 0;
    property var lastWidth : 0

    Pane{
        id:pane
    }

    onWidthChanged: {
        contentX += lastWidth-width
        lastWidth = width;
    }

    ScrollIndicator.vertical: ScrollIndicator{}
    ScrollIndicator.horizontal: ScrollIndicator{}
}

我是这样使用它的:

    ScrollableItem{
       width : parent.width
       height : parent.height

       LayoutMirroring.enabled: true
       LayoutMirroring.childrenInherit: true

       RowLayout{
          spacing: 500
          layoutDirection: Qt.RightToLeft
          Button{
          }
          Button{
          }
          Button{
          }
       }
    }

这对我来说效果很好。当pane的宽度小于Flickable时,您应该将剩余的space添加到leftMargin以保持内容在右侧。