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
We are designing for a 1920×1080 screen resolution, and this is the code we use to set the whole body size.
- id: mainWindow
- width: 1920
- height: 1080
- color: "#000000"
- anchors.fill: parent
This is the result of the preview:

We want this thing to work in different screen sizes. So is there any code to make it fit to screen?
Thanks!
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.
- view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
- view.setGeometry(application.desktop()->screenGeometry());
You probably need to set some window flags correctly (eg. Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint)
The documentation about QWidget::showFullScreen() says that …
- 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.
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.
Ok.. seems this have a problem. I tried the below code and seems to work. Can you try..
- #include <QDeclarativeView>
- QDeclarativeView *viewer = new QDeclarativeView;
- viewer->setResizeMode(QDeclarativeView::SizeRootObjectToView);
- 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
- Item {
- height: 100; width: 100 // some default
- .......
- }
This is strange that showFullScreen() in QWidget ( I mean QDeclarativeView) does not work.
You must log in to post a reply. Not a member yet? Register here!

