0

我有一个 2x2 网格布局。所有项目都左对齐,每列占据 50% 的空间。

现在我想将 GridLayout 的 4 个项目之一向右移动 20 像素。我该怎么做?

import QtQuick 2.2 
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1

Gridlayout {
   rows: 2
   flow: GridLayout.TopToBottom
   TextEdit {
      Layout.alignment: Qt.AlignLeft
      text: "test 1"
   }
   Image {
      // This one is supposed to be aligned left + 20 pixels
      source: "cool-pic.jpg"
   }
   TextEdit {
      Layout.alignment: Qt.AlignLeft
      text: "test 3"
   }
   TextEdit {
      text: "test 4"
   }
}     
4

1 回答 1

1

我找到了这个解决方案。它有效,也许对您有用。您可以根据需要更改宽度

import QtQuick 2.2
import QtQuick.Layouts 1.1

GridLayout {
   rows: 2
   flow: GridLayout.TopToBottom
   TextEdit {
      Layout.alignment: Qt.AlignLeft
      text: "test 1"
   }

   Row{
       Rectangle{width: 20;height:parent.height; color:"transparent"}
   Image {
      // This one is supposed to be aligned left + 20 pixels
      source: "sub/tst.jpg"
   }
   }
   TextEdit {
      Layout.alignment: Qt.AlignLeft
      text: "test 3"
   }
   TextEdit {
      text: "test 4"
   }
}
于 2014-09-14T18:23:29.050 回答