QML关于screen的相关问题

lishadowl 2019-10-15 10:30:34
正在自学qml,网上只找到一个很古老版本(qt5.0还是.1吧)的,里面在设置长宽的时候用了Screen.width和Screen.height,我在5.12用的时候发现Screen里没有长宽,不过ScreenInfo里面有,但是不能用于直接设置窗口的长宽,请问应该如何解决?虽然目测是版本变化造成的,但是我也暂时没找到相关的信息,如能解答,感激不尽。
另外如果需要看代码和报错我会尽快截图发上来。另外QML也是Qt的,发这里应该……没错吧?
...全文
580 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lishadowl 2019-10-16
  • 打赏
  • 举报
回复
引用 1 楼 这是一个正经昵称 的回复:
具体Screen怎么用呢,可以去官网文档找Qt5.12->QML->Screen 文档一般说的够清楚的,需要import对应的包,然后你就可以使用了。 QML经常会出现这种无法自动填充的问题,自己手打Screen.width就行了,just do it。 然后你就可以看到想要的大小了。 此例图截取自Qt5.13版本QML文档,要求import 2.13代码中我import的是2.3,一样可以用。
另外我之前翻帮助文档看到了这些,结果最后是这些没有代码提示坑了我…心情很复杂…
lishadowl 2019-10-16
  • 打赏
  • 举报
回复
被代码提示坑了我也很绝望啊QAQ,自学的菜鸟遇到这种问题第一反应是自己什么做错了而不是软件出问题了,另外谢谢dalao的指点,受教了
  • 打赏
  • 举报
回复
具体Screen怎么用呢,可以去官网文档找Qt5.12->QML->Screen 文档一般说的够清楚的,需要import对应的包,然后你就可以使用了。 QML经常会出现这种无法自动填充的问题,自己手打Screen.width就行了,just do it。 然后你就可以看到想要的大小了。 此例图截取自Qt5.13版本QML文档,要求import 2.13代码中我import的是2.3,一样可以用。
lishadowl 2019-10-16
  • 打赏
  • 举报
回复
引用 5 楼 astro_lee 的回复:
Component {
name: "QQuickScreenAttached"
prototype: "QQuickScreenInfo"
Property { name: "orientationUpdateMask"; type: "Qt::ScreenOrientations" }
Property { name: "height"; type: "int"; isReadonly: true }
Property { name: "width"; type: "int"; isReadonly: true }

Method {
name: "angleBetween"
type: "int"
Parameter { name: "a"; type: "int" }
Parameter { name: "b"; type: "int" }
}
}
好的,谢谢大佬
ly1chee 2019-10-16
  • 打赏
  • 举报
回复
Component {
name: "QQuickScreenAttached"
prototype: "QQuickScreenInfo"
Property { name: "orientationUpdateMask"; type: "Qt::ScreenOrientations" }
Property { name: "height"; type: "int"; isReadonly: true }
Property { name: "width"; type: "int"; isReadonly: true }

Method {
name: "angleBetween"
type: "int"
Parameter { name: "a"; type: "int" }
Parameter { name: "b"; type: "int" }
}
}
ly1chee 2019-10-16
  • 打赏
  • 举报
回复
代码自动完成没有提示,你可以手动修改qmltypes,以我的5.12.5(msvc2017 32bit)版本为例
编辑:C:\Qt\Qt5.12.5\5.12.5\msvc2017\qml\QtQuick\Window.2\plugins.qmltypes
找到QQuickScreenAttached,将这个组件的代码修改如下:
Component {
name: "QQuickScreenAttached"
prototype: "QQuickScreenInfo"
Property { name: "orientationUpdateMask"; type: "Qt::ScreenOrientations" }
Property { name: "height"; type: "int"; isReadonly: true }
Property { name: "width"; type: "int"; isReadonly: true }

Method {
name: "angleBetween"
type: "int"
Parameter { name: "a"; type: "int" }
Parameter { name: "b"; type: "int" }
}
}

插入红色这2行代码,保存之后重启QtCreator,不出意外输入Screen.后面的自动完成列表中就有width和height这2个属性了,另外这个Screen类型还有其他附加属性也可以按照这个方法添加。

21,475

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧