×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    16

    Question How to manage layout of widgets for different orientations?

    Hi,
    I am using Qt Garden release. I have created a dialog using QDialog, and inside this dialog I have several other widgets (like Pushbutton, labels etc). But I am not getting the way to display this dialog properly for different orientations (landscape, portrait and for different screen resolutions). I tried by setting size policy for every widget using setSizepolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)), but no success.

    Please suggest me other ways to control widget's size.

    Thanks in advance
    Sumit
    Last edited by sumitsasken; 2009-03-23 at 06:49.

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    ભારત->ગુજરાત->ભાવનગર
    Posts
    279

    Smile Re: How to manage layout of widgets for different orientations?

    Quote Originally Posted by sumitsasken View Post
    Hi,
    I am using Qt Garden release. I have created a dialog using QDialog, and inside this dialog I have several other widgets (like Pushbutton, labels etc). But I am not getting the way to display this dialog properly for different orientations (landscape, portrait and for different screen resolutions). I tried by setting size policy for every widget using setSizepolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)), but no success.

    Please suggest me other ways to control widget's size.

    Thanks in advance
    Sumit
    hii
    Why don't you use QFormLayout to set all the widget in the proper manner,because when you are goin to change the resolution the widget size will set according to it.

    Please have a lot at the code given below:

    Code:
    #include <QtGui>
    #include <QApplication>
    #include<QDialog>
    #include<QPushButton>
    #include<QLabel>
    #include<QFormLayout>
    #include<QWidget>
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QDialog *dial=new QDialog();
        QFormLayout *lay=new QFormLayout();
        QPushButton *push=new QPushButton("Hello World");
        QLabel *lbl=new QLabel("Hellooooooo");
        QWidget *win=new QWidget();
        lay->addRow(lbl,push);
        win->setLayout(lay);
        win->show();
        return a.exec();
    }
    Hope This will help you

    Regards
    Viral parmar

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: How to manage layout of widgets for different orientations?

    Hi,

    This is not an easy problem. Some layouts will work OK at different orientations and resolutions and others will not.

    It may be that you need to create separate layouts and dynamically switch between them when the orientation of the device changes.

    There should be some developer guidelines for this at some point in the future but for now you'll have to experiment. The size policy will help to some extent, as will using multiple nested layouts to get things to expand in the right places.

    Hope that helps,
    Mark

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    16

    Re: How to manage layout of widgets for different orientations?

    Hi Mark
    Thanks for your reply.

    It may be that you need to create separate layouts and dynamically switch between them when the orientation of the device changes.
    How our app can know about change in device's orientation? Is there any fucntion which we can override in our application, like HandleResourceChangeL()? If there is one, we can manually set layout.

    Also, it is mentioned in Garden's release notes that change in orientation is supported.

    Viral >> I tried using QFormLayout, but the result is same.

    Sumit

  5. #5
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: How to manage layout of widgets for different orientations?

    I haven't actually had time to look at the details yet, but presumably the main window/widget's size gets changed by the underlying HandleResourceChangeL() from Symbian OS. Since QWidgets draw into CCoeControls now, the orientation flip will get handled automatically but you should be able to detect and respond to the size change.

    Mark

  6. #6
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    286

    Re: How to manage layout of widgets for different orientations?

    You will get QResizeEvent for each widget.

  7. #7
    Registered User
    Join Date
    Jan 2009
    Posts
    16

    Re: How to manage layout of widgets for different orientations?

    Hi
    I have implementd QWidget's resizeEvent() in my app. But, it is called two times for change in orientation, and with different values of width and height in every call.

    why resizeEvent() called two times?
    why it is giving different values for width and height in same orientation?
    Please clarify.

    Anyways, I am able to manage my app's layout

    thanks
    Sumit

  8. #8
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    286

    Re: How to manage layout of widgets for different orientations?

    Quote Originally Posted by sumitsasken View Post
    why resizeEvent() called two times?
    why it is giving different values for width and height in same orientation?
    Please clarify.
    I consider this as a bug. If you look at the code generating those events you can see why it gets generated twice and why it has 2 sizes although it shouldn't.

    -Janne

  9. #9
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    430

    Re: How to manage layout of widgets for different orientations?

    Quote Originally Posted by mind_freak View Post
    Code:
     
        QDialog *dial=new QDialog();
        QFormLayout *lay=new QFormLayout();
        QPushButton *push=new QPushButton("Hello World");
        QLabel *lbl=new QLabel("Hellooooooo");
        QWidget *win=new QWidget();
        lay->addRow(lbl,push);
        win->setLayout(lay);
        win->show();
        return a.exec();
    }
    You should seriously think about deleting any heap allocated objects after use. The proper Qt-way to do so would be to not create the dialog on the heap, but on the stack and pass a pointer to the dialog to the constructor of every child object you create as parent pointer. I have read that stack-memory is quite rare on S60 so there might be motivation for not creating objects on the stack. Anyway: Either delete them or use the new QScopedPointer which was I think introduced for exactly that purpose.

    To add something to the topic:
    Have a look at the TubeWiz-Example: They prevent automatic screen rotation and use QGraphicsView to do animated screen rotation on their own.
    Last edited by axeljaeger; 2009-07-05 at 15:59. Reason: Add something to the topic.

Similar Threads

  1. s60 widgets development
    By ambatisreedhar in forum Symbian
    Replies: 3
    Last Post: 2009-09-25, 14:41
  2. Announcing the Winners of the WidSets widgets coding contest
    By Maveric in forum Widsets Development
    Replies: 0
    Last Post: 2008-07-04, 10:05
  3. Stair case Layout in wtk(2.2)
    By saqib_ch in forum Mobile Java General
    Replies: 0
    Last Post: 2006-04-04, 08:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×