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. Customize Textfield
Forum Updated to NodeBB v4.3 + New Features

Customize Textfield

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 699 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    Hello guys I want make text input like image. Everything is but I don't set placeholder text. How can I set the placeholder on top like image?

    alt text

    alt text

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Have idea ?

      J.HilkJ 1 Reply Last reply
      0
      • ? A Former User

        Have idea ?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @NullByte said in Customize Textfield:

        Have idea ?

        TextField has a placeHolderText property, did you set that to a value ?

        https://doc.qt.io/qt-5/qml-qtquick-controls-textfield.html#placeholderText-prop


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        1
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Thank you but that's not the problem. How can I show the placeholder on top like in the photo?

          L 1 Reply Last reply
          0
          • ? A Former User

            Thank you but that's not the problem. How can I show the placeholder on top like in the photo?

            L Offline
            L Offline
            lemons
            wrote on last edited by
            #5

            @NullByte
            you could do something like this:

            TextField {
                id: textField
                anchors.centerIn: parent
                focus: false
                width: 150
                height: 40
                text: ""
                color: "#2C2E35"
                // hide placeholder inside input as soon as it gets focus
                placeholderTextColor: textField.activeFocus ? "transparent" : "#AAAAAA"
                placeholderText: "Parola"
                leftPadding: 10
                rightPadding: 10
                topPadding: 5
                bottomPadding: 5
                background: Rectangle {
                    color: "transparent"
                    radius: 15
                    border.width: 2
                    border.color: textField.activeFocus ? "#80BBB6" : "#AAAAAA"
                    
                    // overlay for border line where label should go
                    Rectangle {
                        visible: textField.activeFocus
                        // if background behind input is other than white, apply it here
                        color: "white"
                        anchors.top: parent.top
                        anchors.left: parent.left
                        // move it outside the rounded border
                        anchors.leftMargin: parent.radius
                        width: childrenRect.width
                        height: parent.border.width
                        
                        // the actual label on the border
                        Text {
                            // add some spacings beside the label
                            padding: 5
                            anchors.verticalCenter: parent.verticalCenter
                            text: textField.placeholderText
                            color: "#80BBB6"
                        }
                    }
                }
                cursorDelegate: Rectangle {
                    visible: textField.cursorVisible
                    color: "#80BBB6"
                    width: textField.cursorRectangle.width
                }
            }
            
            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