June 16, 2011

imma_intern imma_intern
Lab Rat
4 posts

Resizing problems. ):

 

Hi. I’m having trouble doing the whole layout of 1920×1080 on my desktop.
Anyone have any idea on how to resize when previewing it? Like is there any code to fit my whole layout according to different type of screensize?

10 replies

June 16, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
399 posts

Did you not get the question. Can you be bit clear and copy any sample code if possible.

June 16, 2011

imma_intern imma_intern
Lab Rat
4 posts

We are designing for a 1920×1080 screen resolution, and this is the code we use to set the whole body size.

  1. id: mainWindow
  2.     width: 1920
  3.     height: 1080
  4.     color: "#000000"
  5.     anchors.fill: parent

This is the result of the preview:

Example

We want this thing to work in different screen sizes. So is there any code to make it fit to screen?

Thanks!

June 16, 2011

Lukas Geyer Lukas Geyer
Dinosaur Breeder
2074 posts

If you want to show your application full screen you might use QWidget::showFullScreen() (see the documentation for details). In addition, you might grab your screens geomerty using QDesktopWidget::screenGeometry() and resize the widget by yourself.

If you want your QML application to be fullscreen remove the width and height attributes and set the resize mode of the QDeclarativeView to QDeclarativeView::SizeRootObjectToView.

  1. view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
  2. view.setGeometry(application.desktop()->screenGeometry());

You probably need to set some window flags correctly (eg. Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint)

June 16, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
399 posts

About reply should have helped you. Basically you don’t need to specify your mainWindow sizde in qml file.

I use below code generally

  1.  QmlApplicationViewer viewer;
  2.      viewer.setMainQmlFile(QLatin1String("qmlfilerelativepath"));
  3.      viewer.setResizeMode(QDeclarativeView::SizeRootObjectToView);
  4.      viewer.showFullScreen();

The code is self explainable.

June 16, 2011

imma_intern imma_intern
Lab Rat
4 posts

Hi thanks for the reply. However when i tried using the codes given, and error occured.

It says: ‘view’ was not declared in this scope

June 16, 2011

Lukas Geyer Lukas Geyer
Dinosaur Breeder
2074 posts

The documentation about QWidget::showFullScreen() says that …

  1. Full-screen mode works fine under Windows, but has certain problems under X. These problems are due to limitations of the ICCCM protocol that specifies the communication between X11 clients and the window manager. ICCCM simply does not understand the concept of non-decorated full-screen windows. Therefore, the best we can do is to request a borderless window and place and resize it to fill the entire screen. Depending on the window manager, this may or may not work. The borderless window is requested using MOTIF hints, which are at least partially supported by virtually all modern window managers.

I wonder if anyone ever faced such problems.

June 16, 2011

Lukas Geyer Lukas Geyer
Dinosaur Breeder
2074 posts

imma_intern wrote:
Hi thanks for the reply. However when i tried using the codes given, and error occured.

It says: ‘view’ was not declared in this scope

‘view’ is the name of a QWidget (or a subclass) or a QmlApplicationViever, however it may be named in your application. See Vijay’s example, this should work fine for you.

June 16, 2011

imma_intern imma_intern
Lab Rat
4 posts

we tried with both of the codes, and we got the same error.

June 16, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
399 posts

Do you include QmlApplicationViewer header file in your cpp file ?
Hi, this header file is generated as a part of qt quick project ( with c++ class integration) creation in Nokia Qt SDK 1.1.

June 16, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
399 posts

Ok.. seems this have a problem. I tried the below code and seems to work. Can you try..

  1. #include <QDeclarativeView>
  2.     QDeclarativeView *viewer = new QDeclarativeView;
  3.     viewer->setSource(QUrl::fromLocalFile("qml/Example/main.qml"));
  4.     viewer->setResizeMode(QDeclarativeView::SizeRootObjectToView);
  5.     viewer->showMaximized();

And in your main.qml, give some default size to your main item. If you don’t specify any side to root item, the main window is not displayed at all.

main.qml

  1.  
  2.   Item {
  3.       height: 100; width: 100 // some default
  4.     .......
  5.   }

This is strange that showFullScreen() in QWidget ( I mean QDeclarativeView) does not work.

 
  ‹‹ [Solved] Publishing an application      [SOLVED] String conversion ››

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