QML - C++ comunication
-
Hi everyone,
I've just started to develop for Symbian and I downloaded the Qt Creator. It's really helpfull but I'm a beginner in this so I'm really lost.
I have a couple of questions:
The first one, I'm trying to make a gradient background generated by C. It's not a big deal but the main problem its that I have to create it indicating the center and the diameter. I would want to make it dynamic depending on the screen size and an element centered I have in the QML. I tried a lot of things searching in the posts but all the answered failed for me. One of them was this one but it doesn't work for me, I guess because I'm not using it correctly.
@viewer.rootContext()->setContextProperty("mainWindow", this);@
I tried also trying to get the childs of the QML and get the property with this example but viewer.rootObject is not QObject
@/*QObject object = viewer.rootObject();
QObject content = object->findChild<QObject>("content");/@This is my code:
@int main(int argc, char *argv[])
{QApplication app(argc, argv); QRadialGradient radialGrad(175, 200, 400); radialGrad.setColorAt(0, QColor::QColor(40,40,40)); radialGrad.setColorAt(1, Qt::black); QBrush brush(radialGrad); QmlApplicationViewer viewer; viewer.setBackgroundBrush(brush); viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto); viewer.setMainQmlFile(QLatin1String("main.qml")); viewer.showExpanded(); return app.exec();
}
@My other question depends also on this QML - C++ Comunication. I would want to minimize the application instead to kill the proccess. I checked that there is a function in QmlApplicationViewer called showMinimize, but should depend on a button in the QML.
Thank you a lot in advance.
-
Well just in case someone has the same problem I found the solution.
Align the radial gradient it's as easy as to get the screen dimensions with:
@return QApplication::desktop()->screenGeometry();@
That is a QRect so with that you can get the screen size and then set the background.