How can I get the size of the screen

619 views
Skip to first unread message

剑鹏 李

unread,
Oct 18, 2011, 9:58:39 PM10/18/11
to android-qt
In Qml,I must set the width and height.But,Different phone has
different size.How can I get the size of the screen in the source??
Thank you!

Sinitsin Igor

unread,
Oct 18, 2011, 11:14:53 PM10/18/11
to andro...@googlegroups.com

How I can see, you must have different qml for different screen sizes (this I see in qml examples)

19.10.2011 7:58 пользователь "剑鹏 李" <limoo...@gmail.com> написал:

Adam Pigg

unread,
Oct 19, 2011, 1:38:51 AM10/19/11
to andro...@googlegroups.com
how about using the size of the root element, so long as it is set to resize to the view, eg
viewer->setResizeMode(QDeclarativeView::SizeRootObjectToView);

剑鹏 李

unread,
Oct 19, 2011, 4:30:19 AM10/19/11
to android-qt
Now ,I get a solution.
int screenWidth = QApplication::desktop()->width();
int screenHeight = QApplication::desktop()->height();

And then ,I pass these data to the qml

view.rootContext()->setContextProperty("screenWidth",screenWidth);
view.rootContext()->setContextProperty("screenHeight",screenHeight);

And luckily,I work.

On Oct 19, 11:14 am, Sinitsin Igor <igor.m.sinit...@gmail.com> wrote:
> How I can see, you must have different qml for different screen sizes (this
> I see in qml examples)
>
> 19.10.2011 7:58 пользователь "剑鹏 李" <limoonb...@gmail.com> написал:

剑鹏 李

unread,
Oct 19, 2011, 4:31:41 AM10/19/11
to android-qt
Now ,I get a solution.
int screenWidth = QApplication::desktop()->width();
int screenHeight = QApplication::desktop()->height();
And then ,I pass these data to the qml
view.rootContext()->setContextProperty("screenWidth",screenWidth);
view.rootContext()->setContextProperty("screenHeight",screenHeight);
And luckily,It work.

On Oct 19, 1:38 pm, Adam Pigg <pig...@gmail.com> wrote:
> how about using the size of the root element, so long as it is set to resize
> to the view, eg
>
> viewer->setResizeMode(QDeclarativeView::SizeRootObjectToView);
>
> On Wed, Oct 19, 2011 at 4:14 AM, Sinitsin Igor <igor.m.sinit...@gmail.com>wrote:
>
>
>
>
>
>
>
> > How I can see, you must have different qml for different screen sizes (this
> > I see in qml examples)
>
> > 19.10.2011 7:58 пользователь "剑鹏 李" <limoonb...@gmail.com> написал:

剑鹏 李

unread,
Oct 19, 2011, 4:31:41 AM10/19/11
to android-qt
Now ,I get a solution.
int screenWidth = QApplication::desktop()->width();
int screenHeight = QApplication::desktop()->height();
And then ,I pass these data to the qml
view.rootContext()->setContextProperty("screenWidth",screenWidth);
view.rootContext()->setContextProperty("screenHeight",screenHeight);
And luckily,It work.

On Oct 19, 1:38 pm, Adam Pigg <pig...@gmail.com> wrote:
> how about using the size of the root element, so long as it is set to resize
> to the view, eg
>
> viewer->setResizeMode(QDeclarativeView::SizeRootObjectToView);
>
> On Wed, Oct 19, 2011 at 4:14 AM, Sinitsin Igor <igor.m.sinit...@gmail.com>wrote:
>
>
>
>
>
>
>
> > How I can see, you must have different qml for different screen sizes (this
> > I see in qml examples)
>
> > 19.10.2011 7:58 пользователь "剑鹏 李" <limoonb...@gmail.com> написал:

剑鹏 李

unread,
Oct 19, 2011, 4:31:40 AM10/19/11
to android-qt
Now ,I get a solution.
int screenWidth = QApplication::desktop()->width();
int screenHeight = QApplication::desktop()->height();
And then ,I pass these data to the qml
view.rootContext()->setContextProperty("screenWidth",screenWidth);
view.rootContext()->setContextProperty("screenHeight",screenHeight);
And luckily,It work.

On Oct 19, 1:38 pm, Adam Pigg <pig...@gmail.com> wrote:
> how about using the size of the root element, so long as it is set to resize
> to the view, eg
>
> viewer->setResizeMode(QDeclarativeView::SizeRootObjectToView);
>
> On Wed, Oct 19, 2011 at 4:14 AM, Sinitsin Igor <igor.m.sinit...@gmail.com>wrote:
>
>
>
>
>
>
>
> > How I can see, you must have different qml for different screen sizes (this
> > I see in qml examples)
>
> > 19.10.2011 7:58 пользователь "剑鹏 李" <limoonb...@gmail.com> написал:

剑鹏 李

unread,
Oct 19, 2011, 4:31:41 AM10/19/11
to android-qt
Now ,I get a solution.
int screenWidth = QApplication::desktop()->width();
int screenHeight = QApplication::desktop()->height();
And then ,I pass these data to the qml
view.rootContext()->setContextProperty("screenWidth",screenWidth);
view.rootContext()->setContextProperty("screenHeight",screenHeight);
And luckily,It work.

On Oct 19, 1:38 pm, Adam Pigg <pig...@gmail.com> wrote:
> how about using the size of the root element, so long as it is set to resize
> to the view, eg
>
> viewer->setResizeMode(QDeclarativeView::SizeRootObjectToView);
>
> On Wed, Oct 19, 2011 at 4:14 AM, Sinitsin Igor <igor.m.sinit...@gmail.com>wrote:
>
>
>
>
>
>
>
> > How I can see, you must have different qml for different screen sizes (this
> > I see in qml examples)
>
> > 19.10.2011 7:58 пользователь "剑鹏 李" <limoonb...@gmail.com> написал:

剑鹏 李

unread,
Oct 19, 2011, 4:31:41 AM10/19/11
to android-qt
Now ,I get a solution.
int screenWidth = QApplication::desktop()->width();
int screenHeight = QApplication::desktop()->height();
And then ,I pass these data to the qml
view.rootContext()->setContextProperty("screenWidth",screenWidth);
view.rootContext()->setContextProperty("screenHeight",screenHeight);
And luckily,It work.

On Oct 19, 1:38 pm, Adam Pigg <pig...@gmail.com> wrote:
> how about using the size of the root element, so long as it is set to resize
> to the view, eg
>
> viewer->setResizeMode(QDeclarativeView::SizeRootObjectToView);
>
> On Wed, Oct 19, 2011 at 4:14 AM, Sinitsin Igor <igor.m.sinit...@gmail.com>wrote:
>
>
>
>
>
>
>
> > How I can see, you must have different qml for different screen sizes (this
> > I see in qml examples)
>
> > 19.10.2011 7:58 пользователь "剑鹏 李" <limoonb...@gmail.com> написал:
Reply all
Reply to author
Forward
0 new messages