From 68199d7b98a3edb757a3ec3165fb0c7281f7c767 Mon Sep 17 00:00:00 2001 From: ck Date: Tue, 8 Oct 2024 16:09:14 +0800 Subject: [PATCH] fix: placeholder text horizontalAlignment not work remove loader --- qt6/src/qml/TextField.qml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/qt6/src/qml/TextField.qml b/qt6/src/qml/TextField.qml index 073388e8..c2a8c536 100644 --- a/qt6/src/qml/TextField.qml +++ b/qt6/src/qml/TextField.qml @@ -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 {