Add support for -qwindowicon command line argument.
[ChangeLog][QtGui][QGuiApplication] Add support for -icon command line argument on X11, add -qwindowicon on all platforms. Change-Id: Iacc602466699bf634d8b34aab7ed73c83fd9844f Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
parent
9e44204bf8
commit
532b94e98f
@ -495,6 +495,7 @@ static QWindowGeometrySpecification windowGeometrySpecification;
|
||||
\l{Session Management}{session}.
|
||||
\li -qwindowgeometry, sets the geometry of the first window
|
||||
\li -qwindowtitle, sets the title of the first window
|
||||
\li -qwindowicon, sets the default window icon
|
||||
\endlist
|
||||
|
||||
The following standard command line options are available for X11:
|
||||
@ -1115,6 +1116,11 @@ void QGuiApplicationPrivate::createPlatformIntegration()
|
||||
} else if (arg == "-qwindowtitle" || (platformName == "xcb" && arg == "-title")) {
|
||||
if (++i < argc)
|
||||
firstWindowTitle = QString::fromLocal8Bit(argv[i]);
|
||||
} else if (arg == "-qwindowicon" || (platformName == "xcb" && arg == "-icon")) {
|
||||
if (++i < argc) {
|
||||
const QString icon = QString::fromLocal8Bit(argv[i]);
|
||||
forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon);
|
||||
}
|
||||
} else {
|
||||
argv[j++] = argv[i];
|
||||
}
|
||||
|
@ -234,6 +234,7 @@ public:
|
||||
QInputMethod *inputMethod;
|
||||
|
||||
QString firstWindowTitle;
|
||||
QIcon forcedWindowIcon;
|
||||
|
||||
static QList<QObject *> generic_plugin_list;
|
||||
#ifndef QT_NO_SHORTCUT
|
||||
|
@ -436,11 +436,14 @@ void QWindow::setVisible(bool visible)
|
||||
QCoreApplication::removePostedEvents(qApp, QEvent::Quit);
|
||||
|
||||
if (type() == Qt::Window) {
|
||||
QString &firstWindowTitle = QGuiApplicationPrivate::instance()->firstWindowTitle;
|
||||
QGuiApplicationPrivate *app_priv = QGuiApplicationPrivate::instance();
|
||||
QString &firstWindowTitle = app_priv->firstWindowTitle;
|
||||
if (!firstWindowTitle.isEmpty()) {
|
||||
setTitle(firstWindowTitle);
|
||||
firstWindowTitle = QString();
|
||||
}
|
||||
if (!app_priv->forcedWindowIcon.isNull())
|
||||
setIcon(app_priv->forcedWindowIcon);
|
||||
}
|
||||
|
||||
QShowEvent showEvent;
|
||||
|
BIN
tests/auto/gui/kernel/qguiapplication/icons/appicon.png
Normal file
BIN
tests/auto/gui/kernel/qguiapplication/icons/appicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 175 B |
BIN
tests/auto/gui/kernel/qguiapplication/icons/usericon.png
Normal file
BIN
tests/auto/gui/kernel/qguiapplication/icons/usericon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
@ -7,3 +7,5 @@ INCLUDEPATH += $$CORE_TEST_PATH
|
||||
TARGET = tst_qguiapplication
|
||||
QT += gui-private
|
||||
SOURCES += tst_qguiapplication.cpp
|
||||
|
||||
RESOURCES = tst_qguiapplication.qrc
|
||||
|
@ -61,6 +61,7 @@ class tst_QGuiApplication: public tst_QCoreApplication
|
||||
private slots:
|
||||
void displayName();
|
||||
void firstWindowTitle();
|
||||
void windowIcon();
|
||||
void focusObject();
|
||||
void allWindows();
|
||||
void topLevelWindows();
|
||||
@ -95,6 +96,24 @@ void tst_QGuiApplication::firstWindowTitle()
|
||||
QCOMPARE(window.title(), QString("User Title"));
|
||||
}
|
||||
|
||||
void tst_QGuiApplication::windowIcon()
|
||||
{
|
||||
int argc = 3;
|
||||
char *argv[] = { const_cast<char*>("tst_qguiapplication"), const_cast<char*>("-qwindowicon"), const_cast<char*>(":/icons/usericon.png") };
|
||||
QGuiApplication app(argc, argv);
|
||||
QIcon appIcon(":/icons/appicon.png");
|
||||
app.setWindowIcon(appIcon);
|
||||
|
||||
QWindow window;
|
||||
window.show();
|
||||
|
||||
QIcon userIcon(":/icons/usericon.png");
|
||||
// Comparing icons is hard. cacheKey() differs because the icon was independently loaded.
|
||||
// So we use availableSizes, after making sure that the app and user icons do have different sizes.
|
||||
QVERIFY(userIcon.availableSizes() != appIcon.availableSizes());
|
||||
QCOMPARE(window.icon().availableSizes(), userIcon.availableSizes());
|
||||
}
|
||||
|
||||
class DummyWindow : public QWindow
|
||||
{
|
||||
public:
|
||||
|
@ -0,0 +1,6 @@
|
||||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource prefix="/">
|
||||
<file>icons/usericon.png</file>
|
||||
<file>icons/appicon.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
Loading…
Reference in New Issue
Block a user