diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-08-09 15:14:55 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-08-10 22:24:20 +0000 |
commit | 580f2872f09cf7ad83ec9ae5dca686683a3cac80 (patch) | |
tree | 89b39fbd89e360015fac0c3e041b5ea77702f41e /tests/auto/quick/qquicktextinput | |
parent | 5e7720d3fba1865439bf21fd564152b8b9a70f13 (diff) |
TextInput: fix horizontal alignment when implicit resizing is disabled
By default, TextInput updates its implicit width to match the content
width. This implies that when TextInput does not have an explicit width
set, there is no need to handle horizontal alignment.
TextField wants to override the default implicit width, so it disables
the "implicit resizing" feature of TextInput. In this scenario, the
implicit width does not match the content width. Therefore the text
layouting code should also treat the item as if it had an explicit width
set to achieve the correct horizontal alignment.
Task-number: QTBUG-55138
Change-Id: I8c04971a6aff44c6f1734df50153a9788849e98a
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktextinput')
-rw-r--r-- | tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 18ccd81633..ea88f9dadb 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -200,6 +200,8 @@ private slots: void implicitSize(); void implicitSizeBinding_data(); void implicitSizeBinding(); + void implicitResize_data(); + void implicitResize(); void negativeDimensions(); @@ -5967,6 +5969,39 @@ void tst_qquicktextinput::implicitSizeBinding() QCOMPARE(textObject->height(), textObject->implicitHeight()); } +void tst_qquicktextinput::implicitResize_data() +{ + QTest::addColumn<int>("alignment"); + QTest::newRow("left") << int(Qt::AlignLeft); + QTest::newRow("center") << int(Qt::AlignHCenter); + QTest::newRow("right") << int(Qt::AlignRight); +} + +void tst_qquicktextinput::implicitResize() +{ + QFETCH(int, alignment); + + QQmlComponent component(&engine); + component.setData("import QtQuick 2.0\nTextInput { }", QUrl::fromLocalFile("")); + + QScopedPointer<QQuickTextInput> textInput(qobject_cast<QQuickTextInput *>(component.create())); + QVERIFY(!textInput.isNull()); + + QScopedPointer<QQuickTextInput> textField(qobject_cast<QQuickTextInput *>(component.create())); + QVERIFY(!textField.isNull()); + QQuickTextInputPrivate::get(textField.data())->setImplicitResizeEnabled(false); + + textInput->setWidth(200); + textField->setImplicitWidth(200); + + textInput->setHAlign(QQuickTextInput::HAlignment(alignment)); + textField->setHAlign(QQuickTextInput::HAlignment(alignment)); + + textInput->setText("Qt"); + textField->setText("Qt"); + + QCOMPARE(textField->positionToRectangle(0), textInput->positionToRectangle(0)); +} void tst_qquicktextinput::negativeDimensions() { |