This gist allows you to implement a material drawer easily for your projects. It consists of three files:
- PageDrawer.qml The drawer itself, with an icon viewer, a list view and some hacks to execute the actions/functions assigned to each drawer item
- DrawerItem.qml Which can act as an action, a spacer, a separator or a link
- SvgImage.qml Ugly hack to make SVG images look crisp and smooth on HDPI screens
This code is released under the WTFPL, for more information click here.
This Gist requires you to use QtQuick.Controls 2.0
and QtQuick.Layouts 1.0
, however, it could be adapted to work on previous versions of QtQuick.
import QtQuick 2.0
PageDrawer {
id: drawer
//
// Icon properties
//
iconTitle: "Test App"
iconSource: "qrc:/images/logo.png"
iconSubtitle: qsTr ("Version 1.0 Beta")
//
// Define the actions to take for each drawer item
// Drawers 5 and 6 are ignored, because they are used for
// displaying a spacer and a separator
//
actions: {
0: function() { console.log ("Item 1 clicked!") },
1: function() { console.log ("Item 2 clicked!") },
2: function() { console.log ("Item 3 clicked!") },
3: function() { console.log ("Item 4 clicked!") },
4: function() { console.log ("Item 5 clicked!") },
7: function() { console.log ("Item 6 clicked!") },
8: function() { console.log ("Item 7 clicked!") }
}
//
// Define the drawer items
//
items: ListModel {
id: pagesModel
ListElement {
pageTitle: qsTr ("Item 1")
pageIcon: "qrc:/icons/item1.svg"
}
ListElement {
pageTitle: qsTr ("Item 2")
pageIcon: "qrc:/icons/item2.svg"
}
ListElement {
pageTitle: qsTr ("Item 3")
pageIcon: "qrc:/icons/item3.svg"
}
ListElement {
pageTitle: qsTr ("Item 4")
pageIcon: "qrc:/icons/item4.svg"
}
ListElement {
pageTitle: qsTr ("Item 5")
pageIcon: "qrc:/icons/item5.svg"
}
ListElement {
spacer: true
}
ListElement {
separator: true
}
ListElement {
pageTitle: qsTr ("Item 6")
pageIcon: "qrc:/icons/item6.svg"
}
ListElement {
pageTitle: qsTr ("Item 7")
pageIcon: "qrc:/icons/item7.svg"
}
}
}
Awesome work, I like it!