Feature request: several layouts in a single ui file



  • Hello all,
    I'm talking here about widgets-based applications, although it might be relevent too for qml-based applications. And posting in "general" because I think it's truely "general", despite being inspired by mobile (Android) development.

    Here's the point. More and more the computers which run our applications can self-adjust their display according to a "portrait" or "landscape" orientation - tablets and mid-end or high-end phones are actual computers. An application run in fullscreen should adjust itself, its layout, according to this orientation. On the desktop, one can also imagine an application adjusting its layout according to its main window form factor.

    For example, an application can show a row of buttons at the top (or bottom) in a portrait layout, but a column of buttons at the left (or right) in a landscape layout.

    However, when a GUI is designed in QtDesigner, only one layout can be defined. If the application has to adjust itself, this layout needs to be manually destroyed then re-created. It would be nice if it was optionally possible to define more than one layout in an UI file, then have the main container be allowed (optionally) to use one layout or the other according to e.g. an orientation change.

    Maybe this could be achieved by splitting the generated setupUi() method. Something like this:

    @class Ui_My_Widget
    {
    void setupUi(QWidget* My_Widget)
    {
    /* here create the various controls and set common properties /
    }
    void setupPortrait(QWidget
    My_Widget)
    {
    /* apply a layout for portrait orientation /
    }
    void setupLandscape(QWidget
    My_Widget)
    {
    /* apply a layout for landscape orientation */
    }

    virtual bool hasOrientationLayouts() override
    { return true; }

    virtual bool setupOrientationLayout(QWidget* My_Widget) override
    {
    if ( My_Widget->width() > My_Widget->height() )
    this->setupLandscape();
    else
    this->setupPortrait();
    }
    };@

    The hasOrientationLayouts() method would override a virtual method provided in QWidget itself, which would return false by default. Then QWidget::resizeEvent() would call setupOrientationLayout() if hasOrientationLayouts() returns true. Of course setupOrientationLayout() would also be a virtual method in QWidget, doing nothing by default.

    This way QtDesigner can provide two layouts an allows a GUI to automagically adjust itself, or this can be done "by hand" more easily.

    Pushing the idea even further, some properties of some controls might be different according to the layout - e.g. some size policies. Or the size itself may induce some major changes, for example a small window (phone screen) may use tabs, while a large window (desktop or big tablet) may display everything in a single view.

    Any thoughts?

    Regards,


  • Lifetime Qt Champion

    Hi,

    Interesting question ! You might want to bring it to the interest mailing list, you'll find Qt's developers/maintainers (this forum is more user oriented)


  • Moderators

    Nice idea! I can definitely see uses for it in both Widget and QML applications.

    The best place to submit feature requests is at the "issue tracker":https://bugreports.qt-project.org/ ; forum posts will get lost. If you want to discuss it further with Qt's engineers first, subscribe to the "Development mailing list":http://lists.qt-project.org/mailman/listinfo/development and send an email. (Not the Interest mailing list though -- that list is for discussing how to use Qt, just like this forum)


  • Lifetime Qt Champion

    JKSH's right, it's rather for the development list. I've mixed the lists...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.