Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

AppTextEdit

A multi-line TextEdit with a given placeholder text. More...

Import Statement: import Felgo 4.0
Inherits:

TextEdit

Properties

Detailed Description

AppTextEdit is an extension of the basic QML TextEdit for getting multi-line text input from the user. For single-line text input, use AppTextInput.

It adds the ability to display a placeholder text, which is visible as long as the text field is empty. The placeholder text's color and text can be configured using placeholderText and placeholderColor properties.

How do I set a placeholder for the text field?

Input controls like AppTextInput, AppTextField or AppTextEdit own a placeholderText property, which you can use for your placeholder text.

 import Felgo
 import QtQuick

 App {
   AppPage {

     // remove focus from textedit if background is clicked
     MouseArea {
       anchors.fill: parent
       onClicked: textEdit.focus = false
     }

     // background for input
     Rectangle {
       anchors.fill: textEdit
       anchors.margins: -dp(8)
       color: "lightgrey"
     }

     // input
     AppTextEdit {
       id: textEdit
       width: dp(200)
       placeholderText: "What's your name?"
       anchors.centerIn: parent
     }
   }
 }

Use AppTextEdit within a Flickable to create a scrollable fixed-height text field

This example shows how you could wrap an AppTextEdit with an AppFlickable, to create a scrollable multi-line text field. With the cursorInView property, you can also assure that the texf field will automatically scroll as soon as the cursor would leave the view while typing.

 import Felgo
 import QtQuick

 App {
   id: app

   NavigationStack {

     AppPage {
       title: "AppTextEdit"
       backgroundColor: Theme.secondaryBackgroundColor


       // Container for the text field
       Item {
         width: parent.width
         height: dp(150)

         // Background and bottom divider for the scrollable text field
         Rectangle {
           anchors.fill: parent
           color: "#fff"

           Rectangle {
             width: parent.width
             height: px(1)
             anchors.bottom: parent.bottom
             color: Theme.listItem.dividerColor
           }
         }

         // Flickable for scrolling, with text field inside
         AppFlickable {
           id: flick
           anchors.fill: parent
           contentWidth: width
           contentHeight: appTextEdit.height

           AppTextEdit {
             id: appTextEdit
             width: parent.width
             height: Math.max(appTextEdit.contentHeight, flick.height)
             verticalAlignment: TextEdit.AlignTop
             // This enables the text field to automatically scroll if cursor moves outside while typing
             cursorInView: true
             cursorInViewBottomPadding: dp(25)
             cursorInViewTopPadding: dp(25)
             flickable: flick

             text: "test1\ntest2\ntest3\ntest4\ntest5\ntest6\ntest7\ntest8\ntest9\ntest10"
           }
         }

         AppScrollIndicator {
           flickable: flick
         }
       }
     }
   }
 }

More Frequently Asked Development Questions

Find more examples for frequently asked development questions and important concepts in the following guides:

Property Documentation

[since Felgo 2.7.0] cursorColor : color

The color of the cursor that marks the current position in the text input. Matches Theme::inputCursorColor by default.

This property was introduced in Felgo 2.7.0.


[since Felgo 2.17.1] cursorInView : bool

This property is used to ensure the text cursor stays on screen, for example when adding new lines at the bottom of the screen. This works by moving the surrounding flickable element in the opposite direction, to avoid the cursor leaving the screen. You must set the flickable property to use this feature!

This property was introduced in Felgo 2.17.1.

See also flickable, cursorInViewTopPadding, and cursorInViewBottomPadding.


[since Felgo 2.17.1] cursorInViewBottomPadding : real

The bottom padding for keeping the text cursor on screen. If the cursor reaches the bottom of the AppTextEdit + this padding, the flickable will scroll to keep the cursor visible.

This property was introduced in Felgo 2.17.1.

See also cursorInView and cursorInViewTopPadding.


[since Felgo 2.17.1] cursorInViewTopPadding : real

The top padding for keeping the text cursor on screen. If the cursor reaches the top of the AppTextEdit + this padding, the flickable will scroll to keep the cursor visible.

This property was introduced in Felgo 2.17.1.

See also cursorInView and cursorInViewBottomPadding.


[since Felgo 2.17.1] flickable : Flickable

Set the surrounding Flickable to use cursorInView.

This property was introduced in Felgo 2.17.1.

See also cursorInView.


[since Felgo 2.17.0] fontSize : int

Set a device-independent font size. It uses the App::sp() function internally. If you set font.pixelSize directly, this property will have no effect.

By default, the fontSize is 18 on Android and 17 on all other platforms.

This property was introduced in Felgo 2.17.0.


placeholderColor : color

The color for the placeholder text.

The default value is Theme::placeholderTextColor.


placeholderText : string

The text to display as placeholder, when the text field is empty.


placeholderTextItem : alias

Alias to the internal Text item that displays the placeholder text.


Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded