Qt Quick Controls - Text Editor▲
The Text Editor Example presents a sample HTML file using the TextArea control, preserving the HTML formatting. The application comes with two user interfaces; one for traditional desktop platforms with a mouse pointer, and another simpler, touch-oriented version.
Desktop User Interface▲
The desktop version is a complete text editor with capabilities for formatting text, and opening and saving HTML and plain text files. It demonstrates the native-looking dialogs and menus using the Qt Labs Platform module. These types are mostly suitable for desktop platforms with support for multiple top-level windows, a mouse pointer, and moderate screen size.
The desktop UI uses FileDialog for opening and saving files:
FileDialog {
id
:
openDialog
fileMode
:
FileDialog.OpenFile
selectedNameFilter.index: 1
nameFilters
:
["Text files (*.txt)"
, "HTML files (*.html *.htm)"
]
folder
:
StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
onAccepted
:
document.load(file)
}
FileDialog {
id
:
saveDialog
fileMode
:
FileDialog.SaveFile
defaultSuffix
:
document.fileType
nameFilters
:
openDialog.nameFilters
selectedNameFilter.index: document.fileType ===
"txt"
? 0
: 1
folder
:
StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
onAccepted
:
document.saveAs(file)
}
It uses FontDialog and ColorDialog for choosing fonts and colors:
FontDialog {
id
:
fontDialog
onAccepted
:
{
document.fontFamily =
font.family;
document.fontSize =
font.pointSize;
}
}
ColorDialog {
id
:
colorDialog
currentColor
:
"black"
}
It also uses Menu and MenuItem that provide a context menu to format text within:
Menu {
id
:
contextMenu
MenuItem {
text
:
qsTr("Copy"
)
enabled
:
textArea.selectedText
onTriggered
:
textArea.copy()
}
MenuItem {
text
:
qsTr("Cut"
)
enabled
:
textArea.selectedText
onTriggered
:
textArea.cut()
}
MenuItem {
text
:
qsTr("Paste"
)
enabled
:
textArea.canPaste
onTriggered
:
textArea.paste()
}
MenuSeparator {}
MenuItem {
text
:
qsTr("Font..."
)
onTriggered
:
fontDialog.open()
}
MenuItem {
text
:
qsTr("Color..."
)
onTriggered
:
colorDialog.open()
}
}
There is also a standard menubar with more options than the context menu.