[GUI] Handle ampersand in windowTitle

This commit is contained in:
xtemp09
2025-11-21 17:46:24 +07:00
committed by Chris Hennes
parent ac88b1bc6a
commit 6437e17821
3 changed files with 12 additions and 1 deletions

View File

@@ -937,7 +937,9 @@ void RecentFilesAction::setFiles(const QStringList& files)
for (int index = 0; index < numRecentFiles; index++) {
QString numberLabel = numberToLabel(index + 1);
QFileInfo fi(files[index]);
recentFiles[index]->setText(QStringLiteral("%1 %2").arg(numberLabel).arg(fi.fileName()));
QString fileName {fi.fileName()};
fileName.replace(QLatin1Char('&'), QStringLiteral("&&"));
recentFiles[index]->setText(QStringLiteral("%1 %2").arg(numberLabel, fileName));
recentFiles[index]->setStatusTip(tr("Open file %1").arg(files[index]));
recentFiles[index]->setToolTip(files[index]); // set the full name that we need later for saving
recentFiles[index]->setData(QVariant(index));

View File

@@ -527,4 +527,11 @@ QString MDIView::buildWindowTitle() const
return windowTitle;
}
void MDIView::setWindowTitle(const QString& title)
{
QString newerTitle {title};
newerTitle.replace(QLatin1Char('&'), QStringLiteral("&&"));
QMainWindow::setWindowTitle(newerTitle);
}
#include "moc_MDIView.cpp"

View File

@@ -78,6 +78,8 @@ public:
/// build window title
QString buildWindowTitle() const;
/// reimplementation of QWidget::setWindowTitle(const QString &title)
void setWindowTitle(const QString& title);
/// Message handler
bool onMsg(const char* pMsg, const char** ppReturn) override;