Restore support for -title command line argument on X11, add -qwindowtitle.

-title disappeared between Qt4 and Qt5, due to all the refactorings around QPA.
Making the caption of the mainwindow configurable allows custom setups
for specific users or use cases.

[ChangeLog][QtGui][QGuiApplication] Restore support for -title command line
argument on X11, add -qwindowtitle on all platforms.

Change-Id: I73e6bf21248f3419178eba583b257172a175e74e
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Albert Astals Cid <albert.astals@canonical.com>
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
This commit is contained in:
David Faure 2014-01-30 21:59:41 +01:00 committed by The Qt Project
parent eacd58d4e7
commit bf82245baf
4 changed files with 27 additions and 0 deletions

View File

@ -471,6 +471,8 @@ static QWindowGeometrySpecification windowGeometrySpecification;
and will make the application wait until a debugger connects to it.
\li -session \e session, restores the application from an earlier
\l{Session Management}{session}.
\li -qwindowgeometry, sets the geometry of the first window
\li -qwindowtitle, sets the title of the first window
\endlist
\sa arguments()
@ -1033,6 +1035,9 @@ void QGuiApplicationPrivate::createPlatformIntegration()
} else if (arg == "-qwindowgeometry" || (platformName == "xcb" && arg == "-geometry")) {
if (++i < argc)
windowGeometrySpecification = QWindowGeometrySpecification::fromArgument(argv[i]);
} else if (arg == "-qwindowtitle" || (platformName == "xcb" && arg == "-title")) {
if (++i < argc)
firstWindowTitle = QString::fromLocal8Bit(argv[i]);
} else {
argv[j++] = argv[i];
}

View File

@ -231,6 +231,8 @@ public:
static bool noGrab;
QInputMethod *inputMethod;
QString firstWindowTitle;
static QList<QObject *> generic_plugin_list;
#ifndef QT_NO_SHORTCUT
QShortcutMap shortcutMap;

View File

@ -432,6 +432,14 @@ void QWindow::setVisible(bool visible)
// remove posted quit events when showing a new window
QCoreApplication::removePostedEvents(qApp, QEvent::Quit);
if (type() == Qt::Window) {
QString &firstWindowTitle = QGuiApplicationPrivate::instance()->firstWindowTitle;
if (!firstWindowTitle.isEmpty()) {
setTitle(firstWindowTitle);
firstWindowTitle = QString();
}
}
QShowEvent showEvent;
QGuiApplication::sendEvent(this, &showEvent);
}

View File

@ -60,6 +60,7 @@ class tst_QGuiApplication: public tst_QCoreApplication
private slots:
void displayName();
void firstWindowTitle();
void focusObject();
void allWindows();
void topLevelWindows();
@ -83,6 +84,17 @@ void tst_QGuiApplication::displayName()
QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The GUI Application"));
}
void tst_QGuiApplication::firstWindowTitle()
{
int argc = 3;
char *argv[] = { const_cast<char*>("tst_qguiapplication"), const_cast<char*>("-qwindowtitle"), const_cast<char*>("User Title") };
QGuiApplication app(argc, argv);
QWindow window;
window.setTitle("Application Title");
window.show();
QCOMPARE(window.title(), QString("User Title"));
}
class DummyWindow : public QWindow
{
public: