Qt,制作可缩小和扩展的UI

发布于 2024-08-18 23:16:24 字数 2435 浏览 6 评论 0原文

我正在尝试学习如何创建 Qt Symbian 应用程序的布局,以便它能够扩展/收缩并适应不同设备的屏幕尺寸。

在我的默认用户界面中,我添加了一个带有五个选项卡的 QTabWidget,我希望它们适合设备的屏幕。我有两个问题:

  1. 如何使选项卡缩小以始终适合设备的屏幕,或者这是不可能的?如果一台设备的宽度为 240px,另一台设备的宽度为 400px,该怎么办?正如您现在所看到的(诺基亚模拟器),选项卡将转到屏幕之外。 (而且我不想使用 ScrollButtons)

  2. 正如您在图片的红色部分中看到的那样(诺基亚模拟器 )用户界面中有一些我不想要的间距。相反,我希望 QTabWidget 填充整个屏幕(所有红色部分)。

总之,我现在正在学习,如果您能给我一些提示,告诉我在哪里寻找有关构建适合许多设备和屏幕分辨率的 UI 的这些问题的更多信息,那就太好了。谢谢!

这是我的 UI 文件中的代码:

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

在 main.cpp 中,showMaximized() 用于显示我的小部件,因为我还希望菜单按钮位于底部。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里泪两行 2024-08-25 23:16:24

你如何显示小部件?我建议使用 showFullScreen 方法来显示它 - 这可能会做到这一点。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文