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. implicitHeight works differently in different controls
Qt 6.11 is out! See what's new in the release blog

implicitHeight works differently in different controls

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 384 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.
  • I Offline
    I Offline
    imironchik
    wrote on last edited by
    #1

    In main QML I have ApplicationWindow with header

        header: ToolBar {
            id: toolBar
            implicitHeight: minimumCtrlHeight
    
            RowLayout {
                anchors.fill: parent
    
                ToolButton {
                    id: backBtn
                    onClicked: qmlCppSignals.returnBack()
                    enabled: stackView.keyBackEnabled
                    implicitWidth: parent.height
                    implicitHeight: implicitWidth
    
                    Image {
                        id: backBtnImg
                        source: backBtn.enabled ? "qrc:/img/back-enabled_48x48.png" :
                            "qrc:/img/back-disabled_48x48.png"
                        width: parent.width - minimumCtrlHeight / 4
                        height: parent.height - minimumCtrlHeight / 4
                        anchors.centerIn: parent
                    }
                }
    
                Label {
                    text: qsTr( "Stock" )
                    horizontalAlignment: Qt.AlignHCenter
                    verticalAlignment: Qt.AlignVCenter
                    Layout.fillWidth: true
                }
    
                ToolButton {
                    id: menuButton
                    onClicked: menu.open()
                    enabled: true
                    implicitHeight: parent.height
                    implicitWidth: implicitHeight
    
                    Image {
                        id: menuBtnImg
                        width: parent.width - minimumCtrlHeight / 4
                        height: parent.height - minimumCtrlHeight / 4
                        anchors.centerIn: parent
                        source: enabled ? "qrc:/img/menu-enabled_48x48.png" :
                            "qrc:/img/menu-disabled_48x48.png"
                    }
                }
            }
        }
    

    Its implicit height set to minimumCtrlHeight, what is Screen.pixelDensity * 8. Ok, on Android I see 8 mm, fine.

    In the application I have controls with implicitHeight set to minimumCtrlHeight, for example,

            Grid {
                columns: 3
                rowSpacing: 20
                columnSpacing: 20
                verticalItemAlignment: Grid.AlignVCenter
                horizontalItemAlignment: Grid.AlignLeft
    
                Text {
                    text: qsTr( "Port" )
                }
    
                SpinBox {
                    id: portField
                    editable: true
                    from: 1
                    to: 65535
                    value: connectScreen.port
                    textFromValue: function( value ) {
                       return value;
                    }
                    implicitHeight: appWindow.minimumCtrlHeight
                    implicitWidth: pwdField.width
                    //up.indicator.implicitWidth: appWindow.minimumCtrlHeight
                    //down.indicator.implicitWidth: appWindow.minimumCtrlHeight
                }
    
                Rectangle {
                    width: 1
                    height: 1
                }
    
                Text {
                    text: qsTr( "Password" )
                    id: pwdText
                }
    
                TextField {
                    id: pwdField
                    placeholderText: qsTr( "Password" )
                    leftPadding: appWindow.minimumCtrlHeight / 3
                    echoMode: TextInput.Password
                    text: connectScreen.pwd
                    selectByMouse: true
                    mouseSelectionMode: TextInput.SelectCharacters
                    implicitHeight: appWindow.minimumCtrlHeight
                    implicitWidth: content.width - 40 - implicitHeight - pwdText.width
                    verticalAlignment: TextInput.AlignVCenter
                }
    
                Button {
                    id: showHide
                    checkable: true
                    checked: false
                    width: height
                    height: appWindow.minimumCtrlHeight
                    implicitHeight: height
                    implicitWidth: height
    
                    Image {
                        id: img
                        width: parent.width - minimumCtrlHeight / 4
                        height: parent.height - minimumCtrlHeight / 4
                        anchors.centerIn: parent
                        source: "qrc:/img/layer-visible-on_48x48.png"
                    }
    
                    onClicked: {
                        if( checked ) {
                            img.source = "qrc:/img/layer-visible-off_48x48.png"
                            pwdField.echoMode = TextInput.Normal
                        } else {
                            img.source = "qrc:/img/layer-visible-on_48x48.png"
                            pwdField.echoMode = TextInput.Password
                        }
                    }
                }
    
                Rectangle {
                    width: 1
                    height: 1
                }
    
                Button {
                    id: connectBtn
                    text: qsTr( "Connect" )
                    implicitHeight: appWindow.minimumCtrlHeight
                    implicitWidth: pwdField.width
    
                    onClicked: {
                        showHide.checked = false
                        pwdField.echoMode = TextInput.Password
                        qmlCppSignals.connectRequest( pwdField.text, portField.value )
                    }
                }
    
                Rectangle {
                    width: 1
                    height: 1
                }
            }
    

    And controls are with height less than 8 mm. Look at screenshot.

    Screenshot

    Why it's so? How can I fix it?

    1 Reply Last reply
    0
    • I Offline
      I Offline
      imironchik
      wrote on last edited by
      #2

      Thanks to Mitch Curtis. He answered me:

      However, it's working as expected: the size of the Button is as you requested. However, because the Material style Button uses positive insets for the elevation drop shadow effect, the background is pushed inwards:

      https://doc.qt.io/qt-6/qml-qtquick-controls2-control.html#control-layout

      Oh, right, I forgot to mention the solution: set topInset and bottomInset to 0.

      1 Reply Last reply
      1

      • Login

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