Qt 消失对象

Qt 消失对象,qt,qml,Qt,Qml,我对消失的物品有意见。如果只有“loginBox”-看起来很好: 但当我添加“savedAccountsBox”时,“loginBox”消失,只有“savedAccountsBox”: 此外,结构似乎很好: 怎么了? 这是我的代码: ApplicationWindow { id: applicationWindow1 visible: true width: 640 height: 480 title: qsTr("Hello World")

我对消失的物品有意见。如果只有“loginBox”-看起来很好: 但当我添加“savedAccountsBox”时,“loginBox”消失,只有“savedAccountsBox”: 此外,结构似乎很好:

怎么了? 这是我的代码:

ApplicationWindow {
    id: applicationWindow1
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }


    GridLayout {
            anchors.fill: parent
            //anchors.margins: 20
            //rowSpacing: 20
            //columnSpacing: 20
            //flow:  width > height ? GridLayout.LeftToRight : GridLayout.TopToBottom

            TabView {
                Layout.fillWidth: true
                Layout.fillHeight: true
                Tab {
                    title: "Accounts"

                    GroupBox {
                        id: loginBox
                        x: parent.width * 0.05
                        y: parent.height * 0.05
                        width:  parent.width * 0.4
                        height: parent.height * 0.9
                        title: "Login"

                        TextArea {
                            id: textArea1
                            x: parent.width * 0.125
                            y: parent.height * 0.125
                            width:  parent.width * 0.15
                            height: parent.height * 0.07
                        }
                    }

                    GroupBox {
                        id: savedAccountsBox
                        x: parent.width * 0.6
                        y: parent.height * 0.05
                        width:  parent.width * 0.3
                        height: parent.height * 0.9
                        title: "Saved Accounts"

                        ListView {
                            id: listView1
                            x: parent.width * 0.1
                            y: 0
                            displayMarginBeginning: -50
                            //anchors.centerIn: parent
                            width:  parent.width * 0.5
                            height: parent.height * 0.7
                            spacing: 10
                            scale: 1.6
                            delegate: Item {
                                x: 5
                                width: 80
                                height: 40
                                Row {
                                    id: row1
                                    spacing: 10
                                    Rectangle {
                                        width: 40
                                        height: 40
                                        color: colorCode
                                    }

                                    Text {
                                        text: name
                                        font.bold: true
                                        anchors.verticalCenter: parent.verticalCenter
                                    }
                                }
                            }

                            model: ListModel {
                                ListElement {
                                    name: "Grey"
                                    colorCode: "grey"
                                }

                                ListElement {
                                    name: "Red"
                                    colorCode: "red"
                                }

                                ListElement {
                                    name: "Blue"
                                    colorCode: "blue"
                                }
                            }
                        }
                    }

                }




                Tab {
                    title: "Blue"
                }
                Tab {
                    title: "Green"
                }
            }
    }
}

我建议删除绝对定位和尺寸标注,改用布局

下面是一个代码工作的示例

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Window 2.2
import QtQuick.Layouts 1.1

ApplicationWindow {
    id: applicationWindow1
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }


    GridLayout {
        anchors.fill: parent

        TabView {
            Layout.fillWidth: true
            Layout.fillHeight: true
            Tab {
                title: "Accounts"

                RowLayout {

                    GroupBox {
                        id: loginBox
                        title: "Login"

                        TextArea {
                            id: textArea1
                        }
                    }

                    GroupBox {
                        id: savedAccountsBox
                        title: "Saved Accounts"
                        Layout.fillHeight: true

                        ListView {
                            id: listView1
                            anchors.fill: parent
                            spacing: 10
                            delegate: Item {
                                width: row1.width
                                height: row1.height
                                Row {
                                    id: row1
                                    spacing: 10
                                    Rectangle {
                                        width: 40
                                        height: 40
                                        color: colorCode
                                    }

                                    Text {
                                        text: name
                                        font.bold: true
                                        anchors.verticalCenter: parent.verticalCenter
                                    }
                                }
                            }

                            model: ListModel {
                                ListElement {
                                    name: "Grey"
                                    colorCode: "grey"
                                }

                                ListElement {
                                    name: "Red"
                                    colorCode: "red"
                                }

                                ListElement {
                                    name: "Blue"
                                    colorCode: "blue"
                                }
                            }
                        }
                    }
                }

            }




            Tab {
                title: "Blue"
            }
            Tab {
                title: "Green"
            }
        }
    }
}

我建议删除绝对定位和尺寸标注,改用布局

下面是一个代码工作的示例

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Window 2.2
import QtQuick.Layouts 1.1

ApplicationWindow {
    id: applicationWindow1
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }


    GridLayout {
        anchors.fill: parent

        TabView {
            Layout.fillWidth: true
            Layout.fillHeight: true
            Tab {
                title: "Accounts"

                RowLayout {

                    GroupBox {
                        id: loginBox
                        title: "Login"

                        TextArea {
                            id: textArea1
                        }
                    }

                    GroupBox {
                        id: savedAccountsBox
                        title: "Saved Accounts"
                        Layout.fillHeight: true

                        ListView {
                            id: listView1
                            anchors.fill: parent
                            spacing: 10
                            delegate: Item {
                                width: row1.width
                                height: row1.height
                                Row {
                                    id: row1
                                    spacing: 10
                                    Rectangle {
                                        width: 40
                                        height: 40
                                        color: colorCode
                                    }

                                    Text {
                                        text: name
                                        font.bold: true
                                        anchors.verticalCenter: parent.verticalCenter
                                    }
                                }
                            }

                            model: ListModel {
                                ListElement {
                                    name: "Grey"
                                    colorCode: "grey"
                                }

                                ListElement {
                                    name: "Red"
                                    colorCode: "red"
                                }

                                ListElement {
                                    name: "Blue"
                                    colorCode: "blue"
                                }
                            }
                        }
                    }
                }

            }




            Tab {
                title: "Blue"
            }
            Tab {
                title: "Green"
            }
        }
    }
}

我建议删除绝对定位和尺寸标注,改用布局

下面是一个代码工作的示例

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Window 2.2
import QtQuick.Layouts 1.1

ApplicationWindow {
    id: applicationWindow1
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }


    GridLayout {
        anchors.fill: parent

        TabView {
            Layout.fillWidth: true
            Layout.fillHeight: true
            Tab {
                title: "Accounts"

                RowLayout {

                    GroupBox {
                        id: loginBox
                        title: "Login"

                        TextArea {
                            id: textArea1
                        }
                    }

                    GroupBox {
                        id: savedAccountsBox
                        title: "Saved Accounts"
                        Layout.fillHeight: true

                        ListView {
                            id: listView1
                            anchors.fill: parent
                            spacing: 10
                            delegate: Item {
                                width: row1.width
                                height: row1.height
                                Row {
                                    id: row1
                                    spacing: 10
                                    Rectangle {
                                        width: 40
                                        height: 40
                                        color: colorCode
                                    }

                                    Text {
                                        text: name
                                        font.bold: true
                                        anchors.verticalCenter: parent.verticalCenter
                                    }
                                }
                            }

                            model: ListModel {
                                ListElement {
                                    name: "Grey"
                                    colorCode: "grey"
                                }

                                ListElement {
                                    name: "Red"
                                    colorCode: "red"
                                }

                                ListElement {
                                    name: "Blue"
                                    colorCode: "blue"
                                }
                            }
                        }
                    }
                }

            }




            Tab {
                title: "Blue"
            }
            Tab {
                title: "Green"
            }
        }
    }
}

我建议删除绝对定位和尺寸标注,改用布局

下面是一个代码工作的示例

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Window 2.2
import QtQuick.Layouts 1.1

ApplicationWindow {
    id: applicationWindow1
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }


    GridLayout {
        anchors.fill: parent

        TabView {
            Layout.fillWidth: true
            Layout.fillHeight: true
            Tab {
                title: "Accounts"

                RowLayout {

                    GroupBox {
                        id: loginBox
                        title: "Login"

                        TextArea {
                            id: textArea1
                        }
                    }

                    GroupBox {
                        id: savedAccountsBox
                        title: "Saved Accounts"
                        Layout.fillHeight: true

                        ListView {
                            id: listView1
                            anchors.fill: parent
                            spacing: 10
                            delegate: Item {
                                width: row1.width
                                height: row1.height
                                Row {
                                    id: row1
                                    spacing: 10
                                    Rectangle {
                                        width: 40
                                        height: 40
                                        color: colorCode
                                    }

                                    Text {
                                        text: name
                                        font.bold: true
                                        anchors.verticalCenter: parent.verticalCenter
                                    }
                                }
                            }

                            model: ListModel {
                                ListElement {
                                    name: "Grey"
                                    colorCode: "grey"
                                }

                                ListElement {
                                    name: "Red"
                                    colorCode: "red"
                                }

                                ListElement {
                                    name: "Blue"
                                    colorCode: "blue"
                                }
                            }
                        }
                    }
                }

            }




            Tab {
                title: "Blue"
            }
            Tab {
                title: "Green"
            }
        }
    }
}

如果在另一个对象的定义中声明了一个对象,而没有将其声明为特定属性的值,则会将其指定给值。
选项卡
的默认属性是
sourceComponent
。在您的情况下,将
loginBox
指定给默认属性,然后立即用
savedAccountsBox
覆盖它。要修复它,您应该将两个
GroupBox
包装成一个
项目

Tab {
    title: "Accounts"
    Item {
       GroupBox {
           id: loginBox
       }
       GroupBox {
           id: savedAccountsBox
       }
    }
}

另外,您应该更喜欢锚定和布局,而不是绝对定位。

如果在另一个对象的定义中声明了一个对象,而没有将其声明为特定属性的值,则会将其指定给值。
选项卡
的默认属性是
sourceComponent
。在您的情况下,将
loginBox
指定给默认属性,然后立即用
savedAccountsBox
覆盖它。要修复它,您应该将两个
GroupBox
包装成一个
项目

Tab {
    title: "Accounts"
    Item {
       GroupBox {
           id: loginBox
       }
       GroupBox {
           id: savedAccountsBox
       }
    }
}

另外,您应该更喜欢锚定和布局,而不是绝对定位。

如果在另一个对象的定义中声明了一个对象,而没有将其声明为特定属性的值,则会将其指定给值。
选项卡
的默认属性是
sourceComponent
。在您的情况下,将
loginBox
指定给默认属性,然后立即用
savedAccountsBox
覆盖它。要修复它,您应该将两个
GroupBox
包装成一个
项目

Tab {
    title: "Accounts"
    Item {
       GroupBox {
           id: loginBox
       }
       GroupBox {
           id: savedAccountsBox
       }
    }
}

另外,您应该更喜欢锚定和布局,而不是绝对定位。

如果在另一个对象的定义中声明了一个对象,而没有将其声明为特定属性的值,则会将其指定给值。
选项卡
的默认属性是
sourceComponent
。在您的情况下,将
loginBox
指定给默认属性,然后立即用
savedAccountsBox
覆盖它。要修复它,您应该将两个
GroupBox
包装成一个
项目

Tab {
    title: "Accounts"
    Item {
       GroupBox {
           id: loginBox
       }
       GroupBox {
           id: savedAccountsBox
       }
    }
}

另外,您应该更喜欢锚定和布局,而不是绝对定位。

我建议您使用编辑器而不是设计器。像“width:parent.width*0.4”这样的东西在QML中不是很好的编码样式,所以手工编写正确的代码会更好。我建议您使用编辑器而不是设计器。像“width:parent.width*0.4”这样的东西在QML中不是很好的编码样式,所以手工编写正确的代码会更好。我建议您使用编辑器而不是设计器。像“width:parent.width*0.4”这样的东西在QML中不是很好的编码样式,所以手工编写正确的代码会更好。我建议您使用编辑器而不是设计器。类似于“width:parent.width*0.4”的东西在QML中不是很好的编码样式,所以手工编写正确的代码会更好。