Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Nesting items (e.g. picture inside a picture frame) in QML
Forum Updated to NodeBB v4.3 + New Features

Nesting items (e.g. picture inside a picture frame) in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 126 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    petero3
    wrote on last edited by petero3
    #1

    In QML, what is a better way of creating a reusable picture frame (or nesting items inside other items)?

    By that, I mean that I have something like a picture frame. A picture frame can contain a picture. The picture must fill the picture frame, but it must fill only the inside of the picture frame, not the whole picture frame...

    i.e. the child must not fill the parent. It must fill the space that the parent wants it to fill.

    I could set the margins of the picture to be the same as the thickness of the frame.

    Or as attached, I could create a PictureFrame with a property (let's call it "inner") that is an Item that already has the correct margins. And then fill that.

    It works, but does QML have a more standard way of doing this?
    (Without adding custom properties and without the picture knowing too much about the frame or vice-versa).

    PictureFrame.qml

    import QtQuick
    
    Rectangle {
        id: myframe
        anchors.fill: parent
        color: Qt.color("red")
        property Item inner: myinner
    
        Item {
            id: myinner
            anchors.fill: parent
            anchors.margins: 20
        }
    }
    
    import QtQuick
    
    Item {
        width: 480
        height: 480
    
        PictureFrame {
            Rectangle {
                id: mypicture
                anchors.fill: parent.inner
                color: Qt.color("blue")
            }
        }
    }
    

    Screenshot from 2023-05-31 18-12-01.png

    Qt 6.5.1

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved