diff options
| author | Doris Verria <doris.verria@qt.io> | 2024-09-19 14:54:32 +0200 |
|---|---|---|
| committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-09-20 07:41:41 +0000 |
| commit | 81c176ecf07281cb9c3c9b063d26179ab049feef (patch) | |
| tree | dad03c9de78dad3a2f4c22b0806f504a103a8ce8 | |
| parent | 361264c29cecc83bd53a48c7797d45cbe5958a49 (diff) | |
QMLPreviewer Example: More improvements
- Don't set implicitHeight to controls as the style should choose
valid default heights
- Use a QPushButton instead of a QToolButton in order to show
consistent styling between widgets and quick
- Make the QLineEdit editable so that a focus frame is displayed
around it (we don't show focus frames for read-only line edits in the
macOS style)
- Validate the URL when editing in the line edit is finished
- Add a tooltip to the button that opens the file dialog to make
its purpose more clear
- Fix typo and improve some messages shown in the message boxes
Change-Id: I53095808a76e2615117039363be01cfa4d9f243f
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Reviewed-by: MohammadHossein Qanbari <mohammad.qanbari@qt.io>
(cherry picked from commit 790f16dd54762919c5c2a4bb335ff9b37a9a33a3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 4abb6760b87125a86b7e1e939162c71f4835709a)
5 files changed, 22 insertions, 14 deletions
diff --git a/examples/quick/quickwidgets/qmlpreviewer/resources/default.qml b/examples/quick/quickwidgets/qmlpreviewer/resources/default.qml index 4ab0c68f1b..04d7652a06 100644 --- a/examples/quick/quickwidgets/qmlpreviewer/resources/default.qml +++ b/examples/quick/quickwidgets/qmlpreviewer/resources/default.qml @@ -16,7 +16,6 @@ Rectangle { TextField { id: textField - implicitHeight: 40 Layout.fillWidth: true focus: true @@ -41,7 +40,6 @@ Rectangle { Button { id: button text: qsTr("Click Me!") - implicitHeight: 40 Layout.fillHeight: true focus: true diff --git a/examples/quick/quickwidgets/qmlpreviewer/widgets/editorwidget.cpp b/examples/quick/quickwidgets/qmlpreviewer/widgets/editorwidget.cpp index 4090ad0c2f..d8bdc57cad 100644 --- a/examples/quick/quickwidgets/qmlpreviewer/widgets/editorwidget.cpp +++ b/examples/quick/quickwidgets/qmlpreviewer/widgets/editorwidget.cpp @@ -65,8 +65,8 @@ void EditorWidget::openFile() case StateController::NewState: case StateController::DirtyState: { const auto answer = QMessageBox::question(this, tr("About to Open File"), - tr("There are some unsaved changes. " - "Do you want to discard the changes?"), + tr("You have unsaved changes. " + "Are you sure you want to discard them?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); if (answer != QMessageBox::Yes) diff --git a/examples/quick/quickwidgets/qmlpreviewer/widgets/mainwindow.cpp b/examples/quick/quickwidgets/qmlpreviewer/widgets/mainwindow.cpp index 339379e127..dd7ac192d3 100644 --- a/examples/quick/quickwidgets/qmlpreviewer/widgets/mainwindow.cpp +++ b/examples/quick/quickwidgets/qmlpreviewer/widgets/mainwindow.cpp @@ -88,8 +88,8 @@ void MainWindow::closeEvent(QCloseEvent *event) case StateController::DirtyState: { const QMessageBox::StandardButton answer = QMessageBox::question(this, tr("About to Close"), - tr("There are some unsaved changes. " - "Do you want to close withou saving?"), + tr("You have unsaved changes. " + "Are you sure you want to close without saving?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); if (answer == QMessageBox::Yes) event->accept(); diff --git a/examples/quick/quickwidgets/qmlpreviewer/widgets/patheditwidget.cpp b/examples/quick/quickwidgets/qmlpreviewer/widgets/patheditwidget.cpp index a9c8feeb5c..378e22acce 100644 --- a/examples/quick/quickwidgets/qmlpreviewer/widgets/patheditwidget.cpp +++ b/examples/quick/quickwidgets/qmlpreviewer/widgets/patheditwidget.cpp @@ -7,12 +7,12 @@ #include <QFileDialog> #include <QHBoxLayout> #include <QLineEdit> -#include <QToolButton> +#include <QPushButton> PathEditWidget::PathEditWidget(QWidget *parent) : QWidget{parent} , m_lineEdit{new QLineEdit} - , m_toolButton{new QToolButton} + , m_urlButton{new QPushButton} { initUI(); @@ -48,14 +48,14 @@ void PathEditWidget::initUI() { QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(m_lineEdit, 1); - layout->addWidget(m_toolButton); + layout->addWidget(m_urlButton); layout->setContentsMargins(0,0,0,0); setLayout(layout); m_lineEdit->setPlaceholderText(tr("File Path")); - m_lineEdit->setReadOnly(true); - m_toolButton->setText(tr("...")); + m_urlButton->setText(tr("Choose")); + m_urlButton->setToolTip(tr("Select path to QML file to load")); } void PathEditWidget::setupConnections() @@ -63,7 +63,8 @@ void PathEditWidget::setupConnections() connect(StateController::instance(), &StateController::stateChanged, this, &PathEditWidget::onAppStateChanged); - connect(m_toolButton, &QToolButton::clicked, this, &PathEditWidget::openFileRequested); + connect(m_lineEdit, &QLineEdit::editingFinished, this, &PathEditWidget::validatePath); + connect(m_urlButton, &QPushButton::clicked, this, &PathEditWidget::openFileRequested); } void PathEditWidget::setFilePath(const QString &filePath) @@ -94,3 +95,11 @@ void PathEditWidget::onAppStateChanged(int oldState, int newState) break; } } + +void PathEditWidget::validatePath() +{ + const auto filePath = m_lineEdit->text(); + QUrl url = QUrl::fromUserInput(filePath); + if (url.isValid()) + emit fileSelected(filePath); +} diff --git a/examples/quick/quickwidgets/qmlpreviewer/widgets/patheditwidget.h b/examples/quick/quickwidgets/qmlpreviewer/widgets/patheditwidget.h index eeb4a3b77d..97a5e4cf59 100644 --- a/examples/quick/quickwidgets/qmlpreviewer/widgets/patheditwidget.h +++ b/examples/quick/quickwidgets/qmlpreviewer/widgets/patheditwidget.h @@ -7,7 +7,7 @@ #include <QWidget> class QLineEdit; -class QToolButton; +class QPushButton; class PathEditWidget : public QWidget { @@ -33,10 +33,11 @@ private: private slots: void onAppStateChanged(int oldState, int newState); + void validatePath(); private: QLineEdit *m_lineEdit = nullptr; - QToolButton *m_toolButton = nullptr; + QPushButton *m_urlButton = nullptr; }; #endif // PATHEDITWIDGET_H |
