Mark Summerfield writes:
> I am trying to create a "pure" QML program, so may main.cpp is simply:
> 
>     #include <QGuiApplication>
>     #include <QQmlEngine>
>     #include <QQuickView>
>     int main(int argc, char *argv[])
>     {
>       QGuiApplication app(argc, argv);
>       QQmlEngine engine;
>       QQuickView view(&engine, 0);
>       view.setSource(QUrl("qrc:/myapp.qml"));
>       view.show();
>       return app.exec();
>     }
> 
> In myapp.qml I have:
> 
>     import QtQuick 2.0
>     import QtQuick.Window 2.0
>     Window {
>       title: "Caption"
>       ...
>     }
> 
> But there doesn't seem to be any API for setting the application's icon.
> (I know I could use QApplication, but I am trying to avoid using
> QWidget.)
> 
> Is it possible to set an application icon, and if so, how?

Currently there isn't a way to do it from QML.  This is because we have not 
exposed QIcon as a QtQuick type.  Window icons can be different sizes, 
depending on the context in which the windowing system shows them (as a 
decoration on the title bar, on a task bar or dock, as "tiles" or whatever).  
QIcon allows you to provide multiple image sizes, but we didn't design the QML 
API for that yet.  The simplest is that we could add an image source URL to 
QQuickWindow, you could provide a medium-sized image for the icon, and it can 
be scaled down (as small as 16 pixels sometimes); but the result will be less 
optimal than if you could provide a 16-pixel icon yourself, in addition to the 
larger one.  We will need icons for Actions too, which we are in the process of 
adding to QtQuick.  So my opinion is that we need proper icon objects in 
QtQuick for both use cases.

A QML Window is a QQuickWindow which is a subclass of QWindow, so the method 
you would want to call is QWindow::setIcon(QIcon &).  Maybe you can create a 
subclass of QQuickWindow in C++ which sets the icon, do qmlRegisterType to make 
it available, and instantiate that instead of plain Window? I haven't tried 
that myself, but it seems like it should work.

Sorry it's not straightforward yet, but I think we will need to add the QML 
window icon API as soon as we have the Icon API figured out in general.

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to