January 11, 2012

Matze5590 Matze5590
Lab Rat
44 posts

qml orientation animation

 

hi there,

i started working with qml and got a problem.
i like to animate my ui when the sreenorientation changes. but without black screen.
i have googled a lot, but i can’t get it working.

i tried to do it like the first comment on this [developer.nokia.com] site says.
But i cant get it working because the connect is not possible with my qmlapplicationviewer.
How can i connect a signal of my qmlapplicationviewer to a function in my main.qml?

Thanks in advance!

my main.cpp:

  1. QScopedPointer<QApplication> app(createApplication(argc, argv));
  2. QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
  3. viewer->setMainQmlFile(QLatin1String("qml/Tankinatornew/main.qml"));
  4. viewer->setOrientation(viewer->ScreenOrientationLockPortrait);
  5. viewer->showExpanded();

2 replies

January 12, 2012

Matze5590 Matze5590
Lab Rat
44 posts

ok, i was able to connect the signal to a function.
but now i have another problem.
i created a new class inheriting QDeclarativeView. This class should send a signal when its resizeEvent() is called. but that never happens without showing it. But when i show it i can’t see my viewer, so there is an empty screen. i also tried to set its stylesheet transparent, but then the screen is white.
How can i show “viewer” and let “my” run the resizeEvent on switching the phone?

my code:

  1.     QScopedPointer<QApplication> app(createApplication(argc, argv));
  2.     QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
  3.     viewer->setMainQmlFile(QLatin1String("qml/Tankinatornew/main.qml"));
  4.     viewer->setOrientation(viewer->ScreenOrientationLockPortrait);
  5.     viewer->showExpanded();
  6.     MyClass my;
  7.     //my.showFullScreen();
  8.     QObject *rootObject = dynamic_cast<QObject*>(viewer->getrootObject());
  9.     QObject::connect(&my, SIGNAL(data(QVariant)), rootObject, SLOT(updateori(QVariant)));
  10.  
  11.     return app->exec();

January 12, 2012

sierdzio sierdzio
Area 51 Engineer
4779 posts

I don’t want to get into your code too much, but I can tell you how I did it. A simple, yet powerful solution, totally OS independent.

In my main QML file, I set height and width by reading a property from C++. This property is being updated by a slot that is connected to QWidget::resize() (in this case, that would be QDeclarativeView::resize()).

Also, you’ll need to set this: viewer->setResizeMode(QDeclarativeView::SizeRootObjectToView);

 Signature 

(Z(:^

 
  ‹‹ qt desktop components with user Style      [Solved] Focus handling: MouseArea over a TextInput ››

You must log in to post a reply. Not a member yet? Register here!