QtQuick随笔

一、LayoutMirroring.enabled: true 可以用在Row、Grid、ListView、GridView上用来反转布局。

  可以在不使用弹簧( Item { Layout.fillWidth: true } )的前提下实现OkButton和CancelButton的靠右侧显示。

二、StackLayout里面可以直接写Item或者别的Layout,不用设置width和height,会自动充满整个stackLayout。

三、定义信号只用signal xxx,如果没有参数就不需要在后面写()。调用的时候需要加上()。

四、Qt.binding(function() { return xxx })和直接属性绑定的区别:

  如果A.color = B.color;

    B.color = C.color;直接这样写,如果C的颜色变化,则不会影响到A的颜色变化

  但是A.color = Qt.binding(function() { return B.color });

    B.color = Qt.binding(function() { return C.color });这样写,如果C的颜色变化,则仍会影响到A的颜色变化。

  如果第一种写法调换两行代码的位置,则可以实现相同的功能。

五、自定义一个Separator,可以使用Column然后里面用两个高度为1的Rectangle,一个颜色为#A0A0A0,一个颜色为#FFFFFF,效果和ui里的Line是一样的。

六、xxxx.js中可以throw xxxx + JSON.stringify( xxxx )。调试程序时就会打印出来js中throw这个异常的地方。

七、TextInput-->TextEdit,TextField-->TextArea,箭头左侧为当行编辑器、右侧为多行编辑器。

八、TextEdit中可以使用MouseArea,里面写:

  var linkUrl = parent.linkAt(mouse.x, mouse.y)

  if (linkUrl !== '')

    if (Qt.openUrlExternally(linkUrl) === false)

      console.log('openUrlExternally failed!')

  可以用来在鼠标点击网页链接的时候,直接用本机浏览器打开该链接。

九、

原文地址:https://www.cnblogs.com/wisdomroc/p/12023162.html