QT自用总结

临时搞QT的东西,这方面网上的资料比较散,比较少。任务又比较急。在这里记录自己用到的东西。方便查阅。随时增加。

QT的官方文档  

https://doc.qt.io/qt-5/qmltypes.html 

 

1.横向布局Row,纵向布局Column。常用属性:width,height,x, y

 

2.Rectangle 属性:color

 

3.锚点属性anchors。这个有很多属性,用到的时候网上查吧。感觉QT布局这块挺强大的。

 

4.如何响应点击

                Image
                {       
                    width: 64
                    height: 64
                    source: "assets/vvave.png"
                    fillMode: Image.PreserveAspectFit
                    anchors.horizontalCenter: parent.horizontalCenter

                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            populate(Q.GET.allTracks, false);
                        }
                    }
                }
MouseArea方法介绍
https://blog.csdn.net/dreamsongo/article/details/72934521
 
5.文字
                Text
                {
                    width: parent.width
                    height: 50
                    text: "全部"
                    elide: Text.ElideRight
                    style: Text.Sunken
                    styleColor: '#3B7CFF'
                    verticalAlignment: Text.AlignTop
                    horizontalAlignment: Text.AlignHCenter
                    font
                    {
                        pixelSize: 16
                    }
                    anchors.horizontalCenter: parent.horizontalCenter
                }
 
6.QImage使用应用内的资源 这个资源的路径是qrc中声明的路径
    QImage defaultImage;
    QString defaultFile = QString::fromUtf8(":/assets/cover.png");
    defaultImage.load(defaultFile, "PNG");  
 
7.圆角图片
        Rectangle{ 
                                id:imageRect
                                radius: 12
                                anchors.top: parent.top
                                anchors.left: parent.left
                                width: 154
                                height: 154
                                Image {
                                    id:theimage
                                    anchors.fill: parent
                                    source: musicImage
                                    visible: false
                                }
                                Rectangle{
                                    id:themask
                                    anchors.fill: parent
                                    radius: 12
                                    visible: false
                                }
                                OpacityMask{
                                    source: theimage
                                    maskSource: themask
                                    anchors.fill: theimage
                                    visible: true
                                }
                            }
 
8. 当Slider默认为false,设置为true时,他的宽总是有问题,不是预设值时。也设置implicitWidth就好了
 
9.毛玻璃的效果怎么做?

 

 感谢zhg同学做的效果。

这里分两块,一块是动态的截屏,一块是对截屏进行blur效果。

         background: Rectangle
                            {
                                radius: 18

                                ShaderEffectSource//动态的截图
                                {
                                    id: footerBlur
                                    width: parent.width
                                    visible: false
                                    height: parent.height
                                    sourceItem: wholeScreen//要截取的对象id 
                                    sourceRect: Qt.rect(videoPopup.x, videoPopup.y, width, height)//改对象中的坐标 如果是非全屏对象 需要自己转换坐标
                                }

                                FastBlur{//blue效果
                                    id:fastBlur
                                    anchors.fill: parent
                                    source: footerBlur
                                    radius: 72//128
                                    cached: true
                                    visible: false
                                }
                                Rectangle{//圆角效果
                                    id:maskRect
                                    anchors.fill:fastBlur
                                    visible: false
                                    clip: true
                                    radius: 18
                                }
                                OpacityMask{
                                    id:mask
                                    anchors.fill: maskRect
                                    visible: true
                                    source: fastBlur
                                    maskSource: maskRect
                                }

                                Rectangle{//罩白
                                    anchors.fill: footerBlur
                                    color: "#CCF7F7F7"
                                    radius: 18
                                }
                            }

 

10.从目前的经验来看,新手写qml最好不要用columlayout这类系统封好的控件,因为我们不熟悉不了解,这些控件里面有些属性设置了是不生效的。为了一个新手就老老实实用rectangle就做好了,横竖布局自己用anchors的属性来做。这样较少的出现“灵异事件”。

 

posted @ 2020-11-19 11:05  hjy11593219  阅读(119)  评论(0编辑  收藏  举报