BlinCT
6 апреля 2017 г. 14:43

Компановка обьектов внутри другого в QML

QML

Всем привет. Моя самая больная тема, это настройка QML обьектов) Задача такая, есть rectangle который должен принять высоту в зависимости от высоты детей которые вложены в него. Само собою внешний rectangle должен учитывать высоту уже внутреннего rectangle и кнопки что идет под ним.

Rectangle
{
            height: 140 * mm
            width: 130 * mm
            radius: 2 * mm
            x: (parent.width - width) / 2
            y: (parent.height - root.height) / 2

            color: "#FF4000"

            ColumnLayout
            {
                anchors.fill: parent
                anchors.margins: 2 * mm
                spacing: 2 * mm

                Rectangle
                {
                    id: rectangleMain
                    anchors.top: parent.top
                    anchors.left: parent.left
                    anchors.right: parent.right
                    color: "yellow"

                    Column
                    {
                        anchors.left: parent.left
                        anchors.right: parent.right
                        anchors.verticalCenter: parent.verticalCenter
                        spacing: 3 * mm

                        Rectangle
                        {
                            id: rectangle1
                            color: "#0174DF"

                            anchors.left: parent.left
                            anchors.right: parent.right
                            radius: 3 * mm
                            height: 20 * mm
                            Label
                            {
                                anchors.horizontalCenter: parent.horizontalCenter
                                text: _dialog.title
                                font.pixelSize: 5.1 * mm

                            }
                        }

                        Rectangle
                        {
                            id: rectangle2
                            color: "#0174DF"

                            anchors.left: parent.left
                            anchors.right: parent.right
                            radius: 3 * mm
                            height: 20 * mm

                            Label
                            {
                                anchors.left: parent.left
                                anchors.right: parent.right
                                anchors.fill: parent
                                text: _dialog.sender
                                textFormat: Text.StyledText
                                font.pixelSize: 4.7 * mm
                                wrapMode: Text.WordWrap
                                horizontalAlignment: Text.AlignHCenter

                            }
                        }

                        Rectangle
                        {
                            id: rectangle3
                            color: "#0174DF"

                            anchors.left: parent.left
                            anchors.right: parent.right
                            radius: 3 * mm
                            height: 20 * mm
                            Label
                            {
                                anchors.left: parent.left
                                anchors.right: parent.right
                                text: _dialog.name
                                textFormat: Text.StyledText
                                font.pixelSize: 4.7 * mm
                                wrapMode: Text.WordWrap
                                horizontalAlignment: Text.AlignHCenter

                            }
                        }

                        Rectangle
                        {
                            id: rectangle4
                            color: "#0174DF"

                            anchors.left: parent.left
                            anchors.right: parent.right
                            radius: 3 * mm
                            height: 30 * mm

                            Text
                            {
                                anchors.left: parent.left
                                anchors.right: parent.right
                                text: _dialog.description
                                textFormat: Text.StyledText
                                font.pixelSize: 4.4 * mm
                                width: _dialog.width
                                wrapMode: Text.WordWrap
                                horizontalAlignment: Text.AlignHCenter

                            }
                        }
                    }

                    Layout.fillHeight: true
                }

                RowLayout
                {
                    anchors.horizontalCenter: parent.horizontalCenter
                    spacing: 2 * mm
                    CButton {
                        text: "OK"
                        onClicked: {
                            _dialog.close()
                            _dialog.confirmed()
                        }
                        anchors.centerIn: parent
                        height: 20 * mm
                        width: 50 * mm
//                        Layout.fillWidth: true
                    }
                }
            }
        }
Заранее благодарю.
2
Вопрос задан по статьеQML - Урок 013. Позиционирование в QML с якорями ( Anchors )

Вам это нравится? Поделитесь в социальных сетях!

1
BlinCT
  • 6 апреля 2017 г. 18:06
  • Ответ был помечен как решение.

Вопрос можно считать закрытым. Поигрался немного с

height: childrenRect.height 
И вроде работает)

    Комментарии

    Только авторизованные пользователи могут публиковать комментарии.
    Пожалуйста, авторизуйтесь или зарегистрируйтесь