Results 1 to 6 of 6

Thread: layout change for application

  1. #1
    Join Date
    Jul 2012
    Posts
    14
    Thanked 1 Time in 1 Post
    Platforms
    Unix/X11 Windows

    Post layout change for application

    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 .....

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: layout change for application

    Get the desktop dimensions (QDesktopWidget), compute the orientation, and build one layout or the other (assuming the same layout cannot simply handle the change).

  3. #3
    Join Date
    Jul 2012
    Posts
    14
    Thanked 1 Time in 1 Post
    Platforms
    Unix/X11 Windows

    Default Re: layout change for application

    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..

  4. #4
    Join Date
    Mar 2012
    Location
    India
    Posts
    102
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: layout change for application

    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

  5. #5
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: layout change for application

    Quote Originally Posted by vivek.panchal View Post
    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 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.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,319
    Thanks
    316
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: layout change for application

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. DockWidgetArea change and layout direction change
    By mstegehu in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2012, 21:24
  2. Change layout of QWizard under OS X
    By pacemkr in forum Qt Programming
    Replies: 0
    Last Post: 20th July 2011, 20:12
  3. Mainwindow layout change
    By Anshuman in forum Qt Programming
    Replies: 1
    Last Post: 28th April 2011, 01:33
  4. How to change keyboard layout
    By somename in forum Qt Programming
    Replies: 5
    Last Post: 27th May 2010, 08:36
  5. Dynamically change the layout
    By pippo42 in forum Qt Programming
    Replies: 2
    Last Post: 12th November 2009, 13:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.