Sizing items in Qt Quick 2.0



  • Hello,

    I am trying to give a fixed size to PushButton and GroupBox while coding QML. I am finding that no matter what I put for "height: xx" or "width: xx", the item does not change size. Below is one example for the PushButton:

    @ Button {
    id: connectButton

            width: 100
    
            anchors.right: spacer2.left
            anchors.verticalCenter: parent.verticalCenter
    
            text: qsTr("Connect")
        }@
    

    Could anyone explain why I cannot define a fixed size for anything.

    Thanks



  • Where does you Button come from? Without seeing it's implementation it is impossible to answer this question.



  • [quote author="frederik" date="1389892420"]Where does you Button come from? Without seeing it's implementation it is impossible to answer this question.[/quote]

    The following is the complete code:

    @Rectangle {
    id: root

    width: 750
    height: 360
    
    SplitView {
        anchors.fill: parent
    
        ToolBar {
            id: mainToolBar
    
            width: 60
    
            anchors.top: parent.top
            anchors.bottom: parent.bottom
    
            ColumnLayout {
                //height: parent.height
                //anchors.bottomMargin: 20
    
                ToolButton {
                    id: homeToolButton
                    text: qsTr("HOME")
                    onClicked: root.color = "white"
                }
    
                ToolButton {
                    id: jogToolButton
                    text: qsTr("JOG")
                    onClicked: root.color = "green"
                }
    
                ToolButton {
                    id: defsToolButton
                    text: qsTr("DEFS")
                    onClicked: root.color = "blue"
                }
    
                ToolButton {
                    id: payloadToolButton
                    text: qsTr("PAYLOAD")
                    onClicked: root.color = "red"
                }
    
                ToolButton {
                    id: limitsToolButton
                    text: qsTr("LIMITS")
                    onClicked: root.color = "yellow"
                }
    
                ToolButton {
                    id: programToolButton
                    text: qsTr("PROGRAM")
                    onClicked: root.color = "orange"
                }
    
                ToolButton {
                    id: ioToolButton
                    text: qsTr("I/O")
                    onClicked: root.color = "brown"
                }
    
                ToolButton {
                    text: qsTr("SETTINGS")
                    onClicked: root.color = "black"
                }
    
                ToolButton {
                    id: modeToolButton
                    text: qsTr("MODE")
                    onClicked: root.color = "purple"
                }
            }
        }
    
        RowLayout {
            id: rowLayout1
    
            height: 30
    
            anchors.top: parent.top
            anchors.right: parent.right
            anchors.margins: 10
    
            Text {
                id: gantryText
    
                width: 30
    
                text: qsTr("Gantry:")
    
                anchors.left: parent.left
                anchors.verticalCenter: parent.verticalCenter
            }
    
            ComboBox {
                id: gantryComboBox
    
                model: 5
    
                anchors.left: gantryText.right
                anchors.right: spacer1.left
                anchors.leftMargin: 10
                anchors.verticalCenter: parent.verticalCenter
            }
    
            Text {
                id: spacer1
    
                width: 400
    
                anchors.right: connectButton.left
                anchors.verticalCenter: parent.verticalCenter
            }
    
            Button {
                id: connectButton
    
                width: 100
    
                anchors.right: spacer2.left
                anchors.verticalCenter: parent.verticalCenter
    
                text: qsTr("Connect")
            }
    
            Text {
                id: spacer2
    
                width: 20
    
                anchors.right: disconnectButton.left
                anchors.verticalCenter: parent.verticalCenter
            }
    
            Button {
                id: disconnectButton
    
                width: 100
    
                anchors.right: parent.right
                anchors.verticalCenter: parent.verticalCenter
    
                text: qsTr("Disconnect")
            }
        }
    
        RowLayout {
            anchors.top: rowLayout1.bottom
            anchors.right: parent.right
            anchors.bottom: parent.bottom
            anchors.margins: 10
    
            ColumnLayout {
                anchors.top: parent.top
                anchors.bottom: parent.bottom
                anchors.left: parent.left
                anchors.right: homePosGroupBox.left
                anchors.margins: 10
    
                GroupBox {
                    id: powerGroupBox
    
                    anchors.top: parent.top
                    anchors.bottom: homeGroupBox.top
                    anchors.left: parent.left
                    anchors.right: parent.right
    
                    title: qsTr("Motors")
                }
    
                GroupBox {
                    id: homeGroupBox
    
                    anchors.bottom: parent.bottom
                    anchors.left: parent.left
                    anchors.right: parent.right
                    anchors.topMargin: 10
    
                    title: qsTr("Home")
                }
            }
    
            GroupBox {
                id: homePosGroupBox
    
                width: 350
    
                anchors.top: parent.top
                anchors.bottom: parent.bottom
                anchors.right: parent.right
                anchors.margins: 10
    
                title: qsTr("Home Position")
            }
        }
    }
    

    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.