Skip to content

Commit

Permalink
fix: placeholder text horizontalAlignment not work
Browse files Browse the repository at this point in the history
remove loader
  • Loading branch information
kegechen committed Oct 16, 2024
1 parent 37316c3 commit 68199d7
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions qt6/src/qml/TextField.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@ T.TextField {
verticalAlignment: TextInput.AlignVCenter
onEffectiveHorizontalAlignmentChanged: placeholder.effectiveHorizontalAlignmentChanged()

Loader {
// use Loader will cause placeholdertext horizontalAlignment not work
// QQuickPlaceholderText will assume it's parent item is QQuickTextInput or QQuickTextInput
// see QQuickPlaceholderText::updateAlignment()
PlaceholderText {
id: placeholder
active: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter)
x: control.leftPadding
y: control.topPadding
width: control.width - (control.leftPadding + control.rightPadding)
height: control.height - (control.topPadding + control.bottomPadding)
signal effectiveHorizontalAlignmentChanged

sourceComponent: PlaceholderText {
text: control.placeholderText
font: control.font
color: control.placeholderTextColor
verticalAlignment: control.verticalAlignment
renderType: control.renderType
}
text: control.placeholderText
visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter)
font: control.font
color: control.placeholderTextColor
verticalAlignment: control.verticalAlignment
renderType: control.renderType
}

background: EditPanel {
Expand Down

0 comments on commit 68199d7

Please sign in to comment.