summaryrefslogtreecommitdiffstats
path: root/howtos/create_toolbar/index.rst
blob: 664ad47895390864869dacc0c0a7758fad568e2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
..
    ---------------------------------------------------------------------------
    Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
    All rights reserved.
    This work, unless otherwise expressly stated, is licensed under a
    Creative Commons Attribution-ShareAlike 2.5.
    The full license document is available from
    http://creativecommons.org/licenses/by-sa/2.5/legalcode .
    ---------------------------------------------------------------------------


How to create a toolbar with QML
================================

QML does not provide a standard QML Element ready to use as a typical toolbar. Nevertheless, creating a toolbar should be fairly simple.
Use an `Item` QML element as a top root element that has a default layout for items created for the toolbar.

For example:

.. code-block:: js

    //Toolbar
    Item {
        width: 500; height: 62

        // this default property enables us to create QML Items
        // that will be automatically laid out in the Row element
        // and considered as toolItems
        default property alias toolItems: layout.children


        Row {
            id: layout
            layoutDirection: Qt.RightToLeft

            anchors {
                verticalCenter: parent.verticalCenter;
                left: parent.left; right: parent.right
                leftMargin: 15; rightMargin: 15
            }

            spacing: 20
        }
    }


This is how you would use the above ``Toolbar`` Component:

.. code-block:: js

    Item {
        id: root
        width: 500; height: 600

        Toolbar {
            id: toolbar
            anchors { top: root.top; left: root.left; right: root.right }

            Image {
                id: toolicon
                source: "path/to/icon.png"
            }
        }
    }