Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: placeholder text horizontalAlignment not work #402

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions qt6/src/qml/TextField.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,20 @@ T.TextField {
verticalAlignment: TextInput.AlignVCenter
onEffectiveHorizontalAlignmentChanged: placeholder.effectiveHorizontalAlignmentChanged()

Loader {
// use loader will cause placeholdertext horizontalAlignment not work
// see QQuickPlaceholderText::updateAlignment()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可以写清楚,QQuickPlaceholderText 会假定他的 parent item 是 QQuickText,用了 Loader 会影响它的 parentItem

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
Loading