use a RowLayout for ToolbarLayout
more reliable. also put the first and last buttons at the extremes, the others in the middle
This commit is contained in:
parent
76eaaf61e7
commit
dea284f8f3
@ -18,22 +18,27 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import QtQuick 2.1
|
import QtQuick 2.1
|
||||||
//import "." 2.0
|
import QtQuick.Layouts 1.1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ToolBarLayout is a container for items on a toolbar that automatically
|
* ToolBarLayout is a container for items on a toolbar that automatically
|
||||||
* implements an appropriate layout for its children.
|
* implements an appropriate layout for its children.
|
||||||
* @inherit QtQuick.Row
|
* @inherit QtQuick.Layouts.RowLayout
|
||||||
*/
|
*/
|
||||||
Row {
|
RowLayout {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
visible: false
|
visible: false
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: spacer
|
id: spacer1
|
||||||
width: 10
|
Layout.fillWidth: true
|
||||||
height: 10
|
Layout.fillHeight: true
|
||||||
|
}
|
||||||
|
Item {
|
||||||
|
id: spacer2
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.fillHeight: true
|
||||||
}
|
}
|
||||||
|
|
||||||
QtObject {
|
QtObject {
|
||||||
@ -41,26 +46,36 @@ Row {
|
|||||||
property bool layouting: false
|
property bool layouting: false
|
||||||
function layoutChildren()
|
function layoutChildren()
|
||||||
{
|
{
|
||||||
var numChildren = root.children.length
|
if (layouting) {
|
||||||
if (layouting || parent == null ||
|
return;
|
||||||
root.width == 0 || numChildren < 2) {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
layouting = true
|
layouting = true;
|
||||||
spacer.parent = null
|
|
||||||
|
|
||||||
spacer.width = root.parent.width - root.childrenRect.width -10
|
spacer1.parent = null;
|
||||||
|
spacer2.parent = null;
|
||||||
|
|
||||||
var last = root.children[numChildren-2]
|
var children = Array();
|
||||||
last.parent = null
|
//seems there is no other way to create a copy of the array
|
||||||
spacer.parent = root
|
//as children is not an actual JS array
|
||||||
last.parent = root
|
for (var i = 0; i < root.children.length; ++i) {
|
||||||
layouting = false
|
children.push(root.children[i]);
|
||||||
|
}
|
||||||
|
var numChildren = children.length;
|
||||||
|
|
||||||
|
spacer1.parent = root;
|
||||||
|
|
||||||
|
for (var i = 1; i < numChildren-1; ++i) {
|
||||||
|
children[i].parent = null;
|
||||||
|
children[i].parent = root;
|
||||||
|
}
|
||||||
|
spacer2.parent = root;
|
||||||
|
children[numChildren-1].parent = null;
|
||||||
|
children[numChildren-1].parent = root;
|
||||||
|
layouting = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: internal.layoutChildren()
|
Component.onCompleted: internal.layoutChildren()
|
||||||
onChildrenChanged: internal.layoutChildren()
|
onChildrenChanged: internal.layoutChildren()
|
||||||
onWidthChanged: internal.layoutChildren()
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user