Commit Graph

3 Commits

Author SHA1 Message Date
MohammadHossein Qanbari bd3ad6c71b QML Previewer Example: Prevent unnecessary state changes
Previously, when setting a new file address and pressing the close
button, the focus would move to the quick widget due to
QLineEdit::editingFinished() being called. This triggered an attempt
to close the old file and open the new one, causing unintended state
transitions.

To resolve this, we now reload the file content and update the quick
widget's source without transitioning to CloseState and OpenState. This
is achieved by updating the file path and emitting stateChanged() from
OpenState to OpenState in the StateController, notifying other widgets
to reload their content.

Pick-to: 6.8
Change-Id: Ic623d320fe1736e11fd538a6735632b19c507394
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Reviewed-by: Doris Verria <doris.verria@qt.io>
2024-10-09 16:23:15 +02:00
Doris Verria 790f16dd54 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

Pick-to: 6.8 6.8.0
Change-Id: I53095808a76e2615117039363be01cfa4d9f243f
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Reviewed-by: MohammadHossein Qanbari <mohammad.qanbari@qt.io>
2024-09-19 18:35:25 +02:00
MohammadHossein Qanbari c156fc4527 Add the QMLPreviewer example
The example provides two sections including an editor and a view for QML
codes. The QML codes can be written by the user from scratch and save to
a file, or, it can be loaded from a file. Also, it is possible to save
the changes and see the result in the view side. The application can
detect any changes to the source file outside of itself and reloads the
editor and the view sections.

The editor is QPlainTextEdit and the view is QQuickWidget. The
QQuickWidget is used to embed QML in the application which is a widget
application.

The implemented actions in the example are:
- Open file: to open and load a (.qml) file
- Save file: to save the changes into the opened file or into a new file
- Close file: to close the opened file
- Reload: to discard the changes and to reload the opened file

Pick-to: 6.8
Change-Id: I3106dd78998c4b0e86e21803ccf1bb84205a13a4
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
2024-08-30 00:28:36 +02:00