Last active
September 8, 2022 12:51
-
-
Save vprus/9aa8d9570cdd29f4aeff to your computer and use it in GitHub Desktop.
QML Component that adds a margin around item in layout.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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