Skip to content

Instantly share code, notes, and snippets.

@vprus
Last active September 8, 2022 12:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vprus/9aa8d9570cdd29f4aeff to your computer and use it in GitHub Desktop.
Save vprus/9aa8d9570cdd29f4aeff to your computer and use it in GitHub Desktop.
QML Component that adds a margin around item in layout.
import QtQuick 2.0
/* Adds a margin around any item that is meant to be placed into layout.
Instantiate this component with a single children item.
*/
Item {
id: root
property int margins: 0
Component.onCompleted: {
var child = children[0]
implicitHeight = child.implicitHeight + 2 * margins
implicitWidth = child.implicitWidth + 2 * margins
child.anchors.fill = root
child.anchors.margins = margins
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment