使 QML 文件适合屏幕
我为诺基亚 n8 创建了一个屏幕分辨率为 640 x 360 的应用程序。它包括很多可轻弹、标签等。我希望它在分辨率为 640 x 480 的诺基亚 e6 上运行。
到目前为止,我只是复制了 QML 文件并针对新分辨率对其进行了修改,但它得到了一个每次更新都做这件事有点烦人。我想知道是否有任何简单的方法可以让它自动将输出适应任何屏幕分辨率?或者如果我可以做其他事情来简化我的任务。我不想使用锚点,因为它会使设计 QML 文件变得太复杂。
I have created an application with a screen resolution of 640 x 360 for the nokia n8. It includes a lot of flickables, labels, etc. I want it to run on the nokia e6 with a resolution of 640 x 480.
Up to now I have simply copied the the QML file and modified it for the new resolution but it's getting a little tiresome to do it for each update. I want to know if there is any simple way I can get it to automatically fit the output to any screen resolution? Or if there is something else I can do to simplify my task. I would prefer not to use anchors because it makes it too complicated to design the QML file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如何使用
QApplication::desktop()
->
availableGeometry()
设置应用程序窗口的几何形状?来自文档:
在下面解决您的评论:
QDesktopWidget::availableGeometry() const
中的const
告诉您,您可以非常确定该函数不会改变任何内容。您需要自己调整大小。编辑: QML 文档 应该为您提供自动更改应用程序几何形状所需的信息。您可以从 C++ 更改 QML 对象的几何形状,也可以将可用的屏幕几何形状定义为 Q_PROPERTY 并从 QML 访问它。我推荐前者,因为连接到
signal
QDesktopWidget::workAreaResized
可能会在可用几何形状可能发生变化的移动设备上为您提供帮助。How about using
QApplication::desktop()
->
availableGeometry()
to set the geometry of your application window?From the docs:
Addressing your comment below:
The
const
inQDesktopWidget::availableGeometry() const
tells you that you can be pretty sure that the function doesn't alter anything. You'll need to do the resizing yourself.Edit: The QML docs should give you the information you need to automatically change your application geometry. You could either change the geometry of the QML object from C++ or define your available screen geometry as a
Q_PROPERTY
and access it from QML. I'd recommend the former, as hooking up to thesignal
QDesktopWidget::workAreaResized
might help you on mobile devices where your available geometery may change.实际上,您应该避免逐像素对界面进行硬编码,并开始使用锚点。有些手机将具有另一种屏幕分辨率,然后您必须为每个手机创建新的 QML。使用锚点,您可以让内容填充所有可用空间
Actually you should avoid hardcoding the interface pixel by pixel and start using anchors. Ther will be some phones that have yet another screen resolution and then you have to create new QML for each of them. With anchors you can let the content fill all available space