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. Custom textfield doesn't work in macos whereas it works in linux

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 242 Views
  • 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.
  • T Offline
    T Offline
    tapirath
    wrote on last edited by tapirath
    #1

    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?

    1 Reply Last reply
    0

    • Login

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