Qt,制作可缩小和扩展的UI
我正在尝试学习如何创建 Qt Symbian 应用程序的布局,以便它能够扩展/收缩并适应不同设备的屏幕尺寸。
在我的默认用户界面中,我添加了一个带有五个选项卡的 QTabWidget,我希望它们适合设备的屏幕。我有两个问题:
如何使选项卡缩小以始终适合设备的屏幕,或者这是不可能的?如果一台设备的宽度为 240px,另一台设备的宽度为 400px,该怎么办?正如您现在所看到的(诺基亚模拟器),选项卡将转到屏幕之外。 (而且我不想使用 ScrollButtons)
正如您在图片的红色部分中看到的那样(诺基亚模拟器 )用户界面中有一些我不想要的间距。相反,我希望 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:
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)
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你如何显示小部件?我建议使用 showFullScreen 方法来显示它 - 这可能会做到这一点。
How do you show the widget? I suggest using the showFullScreen method to show it - that might do it.