20 this, &QAction::documentWasModified);
23 setUnifiedTitleAndToolBarOnMac(
true);
36void MainWindow::newFile()
44void MainWindow::open()
53bool MainWindow::save()
55 if (curFile.isEmpty()) {
62bool MainWindow::saveAs()
71void MainWindow::about()
74 tr(
"The <b>Application</b> example demonstrates how to "
75 "write modern GUI applications using Qt, with a menu bar, "
76 "toolbars, and a status bar."));
79void MainWindow::documentWasModified()
84void MainWindow::createActions()
91 openAct =
new QAction(
QIcon(
":/images/open.png"),
tr(
"&Open..."),
this);
93 openAct->setStatusTip(
tr(
"Open an existing file"));
96 saveAct =
new QAction(
QIcon(
":/images/save.png"),
tr(
"&Save"),
this);
98 saveAct->setStatusTip(
tr(
"Save the document to disk"));
101 saveAsAct =
new QAction(
tr(
"Save &As..."),
this);
103 saveAsAct->setStatusTip(
tr(
"Save the document under a new name"));
106 exitAct =
new QAction(
tr(
"E&xit"),
this);
108 exitAct->setStatusTip(
tr(
"Exit the application"));
112 cutAct =
new QAction(
QIcon(
":/images/cut.png"),
tr(
"Cu&t"),
this);
115 cutAct->setStatusTip(
tr(
"Cut the current selection's contents to the "
119 copyAct =
new QAction(
QIcon(
":/images/copy.png"),
tr(
"&Copy"),
this);
121 copyAct->setStatusTip(
tr(
"Copy the current selection's contents to the "
125 pasteAct =
new QAction(
QIcon(
":/images/paste.png"),
tr(
"&Paste"),
this);
127 pasteAct->setStatusTip(
tr(
"Paste the clipboard's contents into the current "
131 aboutAct =
new QAction(
tr(
"&About"),
this);
132 aboutAct->setStatusTip(
tr(
"Show the application's About box"));
135 aboutQtAct =
new QAction(
tr(
"About &Qt"),
this);
136 aboutQtAct->setStatusTip(
tr(
"Show the Qt library's About box"));
139 cutAct->setEnabled(
false);
140 copyAct->setEnabled(
false);
147void MainWindow::createMenus()
150 fileMenu->addAction(
newAct);
151 fileMenu->addAction(openAct);
152 fileMenu->addAction(saveAct);
153 fileMenu->addAction(saveAsAct);
154 fileMenu->addSeparator();
155 fileMenu->addAction(exitAct);
158 editMenu->addAction(cutAct);
159 editMenu->addAction(copyAct);
160 editMenu->addAction(pasteAct);
165 helpMenu->addAction(aboutAct);
166 helpMenu->addAction(aboutQtAct);
169void MainWindow::createToolBars()
171 fileToolBar = addToolBar(
tr(
"File"));
172 fileToolBar->addAction(
newAct);
173 fileToolBar->addAction(openAct);
174 fileToolBar->addAction(saveAct);
176 editToolBar = addToolBar(
tr(
"Edit"));
177 editToolBar->addAction(cutAct);
178 editToolBar->addAction(copyAct);
179 editToolBar->addAction(pasteAct);
182void MainWindow::createStatusBar()
203bool MainWindow::maybeSave()
208 tr(
"The document has been modified.\n"
209 "Do you want to save your changes?"),
224 tr(
"Cannot read file %1:\n%2.")
248 tr(
"Cannot write file %1:\n%2.")
275 if (curFile.isEmpty())
276 shownName =
"untitled.txt";
void closeEvent(QCloseEvent *event) override
[21]
The QAction class provides an abstraction for user commands that can be added to different user inter...
void setStatusTip(const QString &statusTip)
void triggered(bool checked=false)
This signal is emitted when an action is activated by the user; for example, when the user clicks a m...
static void aboutQt()
Displays a simple message box about Qt.
The QCloseEvent class contains parameters that describe a close event.
static QString getSaveFileName(QWidget *parent=nullptr, const QString &caption=QString(), const QString &dir=QString(), const QString &filter=QString(), QString *selectedFilter=nullptr, Options options=Options())
This is a convenience static function that returns a file name selected by the user.
static QString getOpenFileName(QWidget *parent=nullptr, const QString &caption=QString(), const QString &dir=QString(), const QString &filter=QString(), QString *selectedFilter=nullptr, Options options=Options())
This is a convenience static function that returns an existing file selected by the user.
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
static void setOverrideCursor(const QCursor &)
Sets the application override cursor to cursor.
static void restoreOverrideCursor()
Undoes the last setOverrideCursor().
QString errorString() const
Returns a human-readable description of the last device error that occurred.
The QIcon class provides scalable icons in different modes and states.
void setCentralWidget(QWidget *widget)
Sets the given widget to be the main window's central widget.
static StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
static void about(QWidget *parent, const QString &title, const QString &text)
Displays a simple about box with title title and text text.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
The QPlainTextEdit class provides a widget that is used to edit and display plain text.
\inmodule QtCore\reentrant
void setValue(QAnyStringView key, const QVariant &value)
Sets the value of setting key to value.
QVariant value(QAnyStringView key, const QVariant &defaultValue) const
Returns the value for setting key.
\macro QT_RESTRICTED_CAST_FROM_ASCII
void setModified(bool m=true)
void paste()
Pastes the text from the clipboard into the text edit at the current cursor position.
void copyAvailable(bool b)
This signal is emitted when text is selected or de-selected in the text edit.
void copy()
Copies any selected text to the clipboard.
void setPlainText(const QString &text)
Changes the text of the text edit to the string text.
void clear()
Deletes all the text in the text edit.
QString toPlainText() const
QString QTextEdit::toPlainText() const.
QTextDocument * document
the underlying document of the text editor.
void cut()
Copies the selected text to the clipboard and deletes it from the text edit.
QPoint toPoint() const
Returns the variant as a QPoint if the variant has userType() \l QMetaType::QPoint or \l QMetaType::Q...
QSize toSize() const
Returns the variant as a QSize if the variant has userType() \l QMetaType::QSize; otherwise returns a...
GLenum GLuint GLintptr GLsizeiptr size
[1]
QSettings settings("MySoft", "Star Runner")
[0]
QTextStream out(stdout)
[7]