PDA

View Full Version : layout change for application



vivek.panchal
14th August 2012, 04:49
hi all,

how can i make a one common source code for two devices ... one of which having a portrait screen and another having a landscape screen...
when i load that code in portrait device it will load forms according to portrait mode settings .....

ChrisW67
14th August 2012, 05:07
Get the desktop dimensions (QDesktopWidget), compute the orientation, and build one layout or the other (assuming the same layout cannot simply handle the change).

vivek.panchal
14th August 2012, 06:08
hey chris,

i want only one ui file(because ui file is easily modifiable) between two screens. so when i load that code in portrait device it will load portrait ui form and it will change widget positions in portrait ui file when it loads in landscape device .. so is it possible..

Charvi
14th August 2012, 07:36
Okay. Try giving the following switch when you run the binary (executable, though I haven't tried with windows.), I have tried this with linux:

-display transformed:Rot<angle by which you want to rotate the screen>
eg: -display transformed:Rot270 -> this rotates the screen by 270 degrees.

But for this you may have to recompile your libraries with the following switch in the configure statement along with other switches:

-qt-gfx-transformed

yeye_olive
14th August 2012, 09:22
hey chris,

i want only one ui file(because ui file is easily modifiable) between two screens. so when i load that code in portrait device it will load portrait ui form and it will change widget positions in portrait ui file when it loads in landscape device .. so is it possible..
So you want two separate ui files. Well you can add them to your application as usual and, at runtime, follow ChrisW67's suggested use of QDesktopWidget to decide which UI to instantiate and apply to your widget. Check out the documentation (http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html#using-a-pointer-member-variable) and generalize that to allow for two alternative UIs. I believe that there is no common ancestor to these UI classes; you will need distinct delete statements.

Or, if the two widgets have the same elements and just differ by the way they arrange them in a layout, you could forget UI files and put everything in code.

d_stranz
14th August 2012, 16:00
Why would two UI files be needed? If the form uses a grid layout without using horizontal or vertical spacers, then the layout should just expand to fill the form rectangle when the form is resized to fit the display. As ChrisW67 said, you need to use QDesktopWidget to find the screen dimensions and then resize you own widget to fit.

When designing the form, you have to take screen dimensions into account - you can't make the child widgets too wide to fit side-by-side on a portrait screen, and you can't make them too tall to fit on a landscape screen.

The spacing that the grid layout produces may not be very satisfactory from a visual point of view - in portrait mode, all the widgets will spread out vertically, while in landscape mode, they'll have a lot of horizontal space between them.