Get screen size from QML
-
wrote on 21 Jan 2011, 14:37 last edited by
Hello,
how do i set the width / height equal to the screen size in qml?
Cheers
Tom -
wrote on 21 Jan 2011, 15:22 last edited by
run qmlviewer in fullscreen mode
-
wrote on 21 Jan 2011, 15:36 last edited by
Hello,
I am running the QDeclarativeView in Full Screen mode.
But I am trying to set a child widget relative to the full screen Rectangle:
Rectangle {
Myrect1 { } Myrect2 { x: parent.width / 2 }
}
Myrect 2 isn't shown at the right place of the screen.
Cheers
Tom -
wrote on 21 Jan 2011, 17:50 last edited by
Tom,
to make relative width/height to the parent, you can use the code like this
@Rectangle{
// here you need to set the parent width / height properties to use relatively
width: 500
height: 500Myrect1{ } Myrect2{ // set width / height relative to the parent width: parent.width height: parent.height }
}
@ -
wrote on 21 Jan 2011, 17:53 last edited by
Hello,
I know I can do that. But I don't want to set a hard coded number because then I am stuck to one screen size. I want to retrieve the screen size of the device and use that. Would this be possible in plain QML, or do I need to do it in C++ and pass the values to QML?
Cheers
Tom -
wrote on 22 Jan 2011, 11:48 last edited by
Yes, you need to pass the values to QML from c++ look the following:
Obtaining a Desktop Widget
The QApplication::desktop() function is used to get an instance of QDesktopWidget.
The widget's screenGeometry() function provides information about the geometry of the available screens with. The number of screens available is returned by screenCount, and the screenCountChanged() signal is emitted when screens are added or removed. The screen number that a particular point or widget is located in is returned by screenNumber().
-
wrote on 24 Jan 2011, 00:22 last edited by
Hi Tom,
Have you tried setting the SizeRootObjectToView resize mode on your QDeclarativeView? That should ensure that the root object is the same size as the view. With that in place, the easiest way to center a child in its parent is with anchors:
@MyRect { anchors.centerIn: parent }@
you should also be able to center manually with e.g.
@MyRect { x: parent.width/2 - width/2; ... }@
Regards,
Michael -
wrote on 24 Jan 2011, 18:50 last edited by
Hi,
The SizeRootObjectToView works perfectly. Just what I needed.
Cheers
Tom -
wrote on 28 Mar 2013, 21:32 last edited by
Is there a pure QML way to achieve this?
Okay strike that.
-Is there a pure QML way to achieve this?-I found the place where to put the "--fulscreen" parameter in Qt-Creator.
-
wrote on 25 Mar 2014, 15:12 last edited by
Qt 5.x has QML Screen object you can use within an Item.
-
wrote on 3 Dec 2014, 12:26 last edited by
[quote author="AlterX" date="1395760356"]Qt 5.x has QML Screen object you can use within an Item.[/quote]
thanks !!
i just added:
@import QtQuick.Window 2.0@
then set the width/height like :
@ApplicationWindow {
id: applicationWindow1width: Screen.width height: Screen.height@
and it works
-
wrote on 3 Dec 2014, 12:26 last edited by
[quote author="AlterX" date="1395760356"]Qt 5.x has QML Screen object you can use within an Item.[/quote]
thanks !!
i just added:
@import QtQuick.Window 2.0@
then set the width/height like :
@ApplicationWindow {
id: applicationWindow1width: Screen.width height: Screen.height@
and it works
-
wrote on 3 Dec 2014, 16:47 last edited by
Good...so tag thread's title with [SOLVED]
-
wrote on 3 Dec 2014, 16:47 last edited by
Good...so tag thread's title with [SOLVED]