views:

542

answers:

1

I'm trying to learn how to create the layout of my Qt Symbian application so that it will expand/shrink and fit into the screen size of different devices.

In my default ui I have added a QTabWidget with five tabs that I want to fit into the screen of the device. I have two problems:

  1. How can I make the tabs to shrink to always fit into the screen of the device, or is that not possible? What if one device has a width of 240px and another a width of 400px. As you can see now (Nokia Emulator) the tabs go outside of the screen. (And I don't want to use ScrollButtons)

  2. As you can see in the red part of the picture (Nokia Emulator ) there is some spacing in the UI that I don't want. Instead I want the QTabWidget to fill the whole screen (all the red part).

In summary I'm learning right now and it would be great if you could give me some tips about where to look for more info regarding these problems with building an UI that fits into many devices and screen resolutions. Thanks!

This is the code in my UI file:

void setupUi(QMainWindow *UITest)
{
    if (UITest->objectName().isEmpty())
        UITest->setObjectName(QString::fromUtf8("UITest"));
    UITest->resize(284, 167);
    QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    sizePolicy.setHorizontalStretch(0);
    sizePolicy.setVerticalStretch(0);
    sizePolicy.setHeightForWidth(UITest->sizePolicy().hasHeightForWidth());
    UITest->setSizePolicy(sizePolicy);
    centralwidget = new QWidget(UITest);
    centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
    verticalLayout = new QVBoxLayout(centralwidget);
    verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
    tabWidget = new QTabWidget(centralwidget);
    tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
    tabWidget->setTabPosition(QTabWidget::South);
    tabWidget->setUsesScrollButtons(false);
    tab = new QWidget();
    tab->setObjectName(QString::fromUtf8("tab"));
    tabWidget->addTab(tab, QString());
    ...More tabs...        

    verticalLayout->addWidget(tabWidget);

    UITest->setCentralWidget(centralwidget);

    retranslateUi(UITest);

    QMetaObject::connectSlotsByName(UITest);
} // setupUi

void retranslateUi(QMainWindow *UITest)
{
    UITest->setWindowTitle(QApplication::translate("UITest", "UITest", 0, QApplication::UnicodeUTF8));
    UITest->setStyleSheet(QApplication::translate("UITest", "background: red;\n" "padding: 0px;", 0, QApplication::UnicodeUTF8));
    tabWidget->setStyleSheet(QApplication::translate("UITest", "background: white;\n" "margin: 0px;\n" "padding: 0px;", 0, QApplication::UnicodeUTF8));
} // retranslateUi

In main.cpp showMaximized() is used to show my widget as I also want the menu buttons in the bottom.

A: 

How do you show the widget? I suggest using the showFullScreen method to show it - that might do it.

e8johan
In main.cpp showMaximized() is used to show my widget as I also want the menu buttons in the bottom. showFullScreen() didn't do any different than overriding the menu buttons in the bottom. Can you understand why I have this red margin around my QTabWidget? I want it to expend all over the screen.
Martin
Perhaps you could tweak the layout margin...
e8johan
Yes that's what I've been trying to do, but I can't find any margin anywhere, have been using stylesheets and trying with margin: 0px, padding: 0px; Any ideas?
Martin
Go to the object inspector (not the actual form, the hierarchy tree) and select the central widget. Then scroll all the way down in the property editor. There you will find a layout section with all the margins and spacing settings. (Note, if you apply a layout, you need to select something else and then reselect whichever widget you just applied a layout to before you can find these settings).
e8johan
Thanks I got rid of all the spaces by finding the central widgets layout!
Martin