Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Custom textfield doesn't work in macos whereas it works in linux



  • I've created this custom textfield input

    import QtQuick 2.12
    import QtQuick.Controls 2.5
    
    Rectangle {
        property alias textColor: textField.color
        property alias textBold: textField.font.bold
        property alias textSize: textField.font.pointSize
        property alias borderWidth: bottomBorder.height
        property alias borderColor: bottomBorder.color
        property alias borderVisible: bottomBorder.visible
        property alias placeholder: placeholder.text
        property alias text: textField.text
        property alias readOnly: textField.readOnly
    
        color: "#00000000"
    
        Rectangle {
            id: bottomBorder
            color: parent.textColor
            x: 0
            y: parent.height - height
            width: parent.width
            height: 2
        }
    
        Text {
            id: placeholder
            color: "#ffffff"
            opacity: 0.2
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
            anchors {
                fill: parent
                bottomMargin: bottomBorder.height
            }
    
            font {
                bold: textField.font.bold
                family: textField.font.family
                pointSize: textField.font.pointSize
                capitalization: textField.font.capitalization
            }
        }
    
        TextField {
            id: textField
            background: Item { opacity: 0 }
            selectByMouse: true
            maximumLength: 12
            horizontalAlignment: TextInput.AlignHCenter
            verticalAlignment: TextInput.AlignVCenter
            selectionColor: "#ff5555"
            persistentSelection: true
            focus: true
    
            onTextEdited: {
                placeholder.visible = false
            }
    
            onReleased: {
                if (event.button == Qt.RightButton) {
                    contextMenu.x = x + event.x
                    contextMenu.y = y + event.y
                    contextMenu.visible = true
                }
            }
    
            onPressed: {
                if (event.button == Qt.LeftButton) {
                    contextMenu.visible = false
                }
            }
    
            anchors {
                fill: parent
                bottomMargin: bottomBorder.height
            }
    
            font {
                bold: false
                family: "Inconsolata"
                pointSize: 12
                capitalization: Font.AllUppercase
            }
        }
    
        Menu {
            id: contextMenu
            MenuItem {
                text: "&Copy";
                enabled: textField.selectedText
                onTriggered: textField.copy()
            }
            MenuItem{
                text: "&Paste";
                enabled: textField.canPaste
                onTriggered: textField.paste()
            }
        }
    }
    

    I'm using it as

                CustomInput {
                    id: accountPassInput
                    width: 380
                    height: 50
                    textSize: 26
                    textColor: "#e5e2e1"
                    placeholder: "A4GHE345LL3K"
    
                    anchors {
                        centerIn: parent
                        verticalCenterOffset: -80
                    }
                }
    

    In linux it works as expected. There is a placeholder text and it disappears once I write something. however on macos input doesn't work. I can see that the textfield is focused, I can even paste stuff but it won't accept keyboard input.

    Any ideas?


Log in to reply