On Tue, Jan 29, 2013 at 11:05 AM, Rutledge Shawn
<[email protected]> wrote:
> 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.
There's an even simpler way to do it from C++ - just manage the window
there. QQuickView is a window as well, just use that as the window
(instead of having an empty window as well as the Window{}), and call
setIcon on it. That's just adding "view.setIcon(icon);" in your
existing C++ code, and using an Item{} as the root of myapp.qml
instead of Window{}.
> 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.
The Window{} QML API is also really new, so there's a lot more work to
be done with controlling windows from QML. Right now, it's probably
easiest to control the main window from C++.
--
Alan Alpert
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest