Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 41
Registered: ‎09-14-2012
My Device: Playbook 64Gb
My Carrier: n/a
Accepted Solution

Screen orientation in Qt application

Hi

 

Sorry, another Blackberry/Qt issue...

 

Is there some way for a Qt application to get notified when the screen is rotated? At present, it seems that you have to create a QMainWindow (or whatever top-level widget) with a fixed size -- you can't (so far as I can tell) create a widget that snaps to the screen size. So presumably you have to deal with screen rotation in the application. But how?

 

Best wishes

Kevin

 

 

Developer
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: Screen orientation in Qt application

I got QWidget app with fixed size 1024x600, 6 buttons and QTextEdit. I didn't put any orientation specific code or whatever else - app scales normally between portrait and landscape (position/size of components).
Contributor
Posts: 41
Registered: ‎09-14-2012
My Device: Playbook 64Gb
My Carrier: n/a

Re: Screen orientation in Qt application

Now I'm completely confused. If you set a fixed size of 1024x600, and the window still fills the screen when you rotate, then presumably Qt is overriding your size settings? I mean, in portrait orientation it's 600x1024, no?

 

When set a widget size of 1024x600 (i.e., widget.resize(1024,600)), then when I rotate into portrait my widget only fills the top part of the screen, but the bottom part is black and empty. That is, it's keeping the size of 1024x600, which no longer fits the screen.

 

I tried not calling resize() at all, hoping that the system would somehow scale the main window so that it fills the screen; but it doesn't -- it has a default size of about 5 cm square.

 

I wonder if different releases of Qt behave differently in this respect? Or is there something specific you have to have in the descriptor XML to get reorientation to work?

 

 

Developer
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: Screen orientation in Qt application

[ Edited ]

In my bar descriptor I have

<initialWindow>
<systemChrome>none</systemChrome>
<transparent>false</transparent>
<autoOrients>true</autoOrients>
<aspectRatio>landscape</aspectRatio>
</initialWindow>

In main.cpp:


MainWidget w;
w.showMaximized();

In mainwidget.ui (I use standard desktop oriented ui components)


<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWidget</class>
<widget class="QWidget" name="MainWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1024</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>

Contributor
Posts: 41
Registered: ‎09-14-2012
My Device: Playbook 64Gb
My Carrier: n/a

Re: Screen orientation in Qt application

You're a star !

 

It's the 'showMaximzed()' that does it. After that, the main widget will always fit the screen shape. I don't actually need to set an initial size (but from your code, clearly it doesn't hurt to).

 

Thanks. I can't tell you how much time you saved me Smiley Happy

 

Highlighted
Developer
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: Screen orientation in Qt application

No problem mate, we're here to help each other Smiley Happy