当前位置: 首页 > news >正文

QML-项目实战二

简介

使用QML实现AURT(串口)的通信

效果图

代码实现

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15

// import obj2 1.0 //这是普通注册
// import obj3 1.0 //这是使用单例注册

ApplicationWindow {
    width: 800
    height: 600
    visible: true
    title: qsTr("UART Debug Application")
    readonly property int  fiexHeight: 25 //创建只读的数据

    //添加工具栏
    header: ToolBar{
        height: 35
        spacing: 5
        //网格布局
        GridLayout{
            columns: 3
            ToolButton{
                Layout.column: 0 //设置列
                Layout.preferredHeight: 32 //设置高度
                width: 32;height: 32
                // text: qsTr("Start")
                //ToolButton需要设置背景来设置图片
                background: Image{
                    source: "/images/start.png"
                    width:32;height: 32;
                    fillMode: Image.PreserveAspectFit//图像按照比例缩放,不裁剪
                }
            }
            ToolButton{
                Layout.column: 1 //设置列
                Layout.preferredHeight: 32 //设置高度
                width: 32;height: 32
                // text: qsTr("stop")
                //ToolButton需要设置背景来设置图片
                background: Image{
                    source: "/images/stop.png"
                    width:32;height: 32;
                    fillMode: Image.PreserveAspectFit//图像按照比例缩放,不裁剪
                }
            }
            ToolButton{
                Layout.column: 2 //设置列
                Layout.preferredHeight: 32 //设置高度
                width: 32;height: 32
                // text: qsTr("abort")
                //ToolButton需要设置背景来设置图片
                background: Image{
                    source: "abort" //设置别名用别名加载
                    width:32;height: 32;
                    fillMode: Image.PreserveAspectFit//图像按照比例缩放,不裁剪
                }
            }
        } //end GridLayout
    }// end header
    ColumnLayout{
        anchors.fill: parent
        anchors.leftMargin: 5
        anchors.rightMargin: 5
        RowLayout{ //RowLayout todo
            Layout.fillHeight: true
            Layout.fillWidth: true
            //left area
            ColumnLayout{
                Layout.preferredWidth: 260
                Layout.alignment: Qt.AlignTop

                GridLayout{
                    rows: 5
                    GroupBox{
                        Layout.row: 0
                        title: "Uart configuration"
                        Layout.preferredWidth: 240
                        GridLayout{
                            columns: 2
                            rows: 5
                            Label{
                                Layout.column: 0
                                Layout.row: 0
                                Layout.preferredHeight: fiexHeight
                                text: qsTr("uart port")
                            }
                            ComboBox{
                                Layout.column: 1
                                Layout.row: 0
                                Layout.preferredHeight: fiexHeight
                                model:["ttyWK0","ttyWK1","ttyWK2","ttyWK3"]
                            }

                            Label{
                                Layout.column: 0
                                Layout.row: 1
                                Layout.preferredHeight: fiexHeight
                                text: qsTr("bit port ")
                            }
                            ComboBox{
                                Layout.column: 1
                                Layout.row: 1
                                Layout.preferredHeight: fiexHeight
                                model:["ttyWK0","ttyWK1","ttyWK2","ttyWK3"]
                            }

                            Label{
                                Layout.column: 0
                                Layout.row: 2
                                Layout.preferredHeight: fiexHeight
                                text: qsTr("data bit")
                            }
                            ComboBox{
                                Layout.column: 1
                                Layout.row: 2
                                Layout.preferredHeight: fiexHeight
                                model:["5","6","7","8"]
                            }

                            Label{
                                Layout.column: 0
                                Layout.row: 3
                                Layout.preferredHeight: fiexHeight
                                text: qsTr("parit bit")
                            }
                            ComboBox{
                                Layout.column: 1
                                Layout.row: 3
                                Layout.preferredHeight: fiexHeight
                                model:["None","Even","Odd","Mark","Space"]
                            }

                            Label{
                                Layout.column: 0
                                Layout.row: 4
                                Layout.preferredHeight: fiexHeight
                                text: qsTr("stop bit")
                            }
                            ComboBox{
                                Layout.column: 1
                                Layout.row: 4
                                Layout.preferredHeight: fiexHeight
                                model:["1","2"]
                            }
                        }
                    } //end GroupBox 0
                    GroupBox{
                        Layout.row: 1
                        title: "receiving configuration"
                        Layout.preferredWidth: 240
                        GridLayout{
                            columns: 2
                            rows:2
                            Row{
                                Layout.preferredHeight: fiexHeight
                                //这个按钮组可以不使用
                                ButtonGroup{
                                    id:rcvradiogroup
                                }
                                RadioButton{
                                    id:id_rcvascii
                                    text: "ASCII"
                                    checked: true
                                    implicitHeight: 25
                                    Layout.preferredHeight: fiexHeight
                                }
                                RadioButton{
                                    id:id_rcvhex
                                    text: "Hex"
                                    checked: false
                                    implicitHeight: 25
                                    Layout.preferredHeight: fiexHeight
                                }
                            }//end row

                            Column{
                              Layout.row: 1
                              CheckBox{
                                id:outonwline
                                text: "auto lin free "
                                checked: true
                                indicator: Rectangle{
                                    anchors.verticalCenter: parent.verticalCenter
                                    width: 20
                                    height: 15
                                    color: "transparent"
                                    border.color: "black"
                                    Rectangle{
                                        width: 10
                                        height: 8
                                        color: outonwline.checked?"green":"transparent"
                                        anchors.centerIn: parent
                                    }
                                    }
                                }//checkbox 0
                              CheckBox{
                                id:outondisplay
                                text: "display transparent "
                                checked: true
                                indicator: Rectangle{
                                    anchors.verticalCenter: parent.verticalCenter
                                    width: 20
                                    height: 15
                                    color: "transparent"
                                    border.color: "black"
                                    Rectangle{
                                        width: 10
                                        height: 8
                                        color: outondisplay.checked?"green":"transparent"
                                        anchors.centerIn: parent
                                    }
                                    }
                                }//checkbox 1
                              CheckBox{
                                id:outondisplaytime
                                text: "display time "
                                checked: true
                                indicator: Rectangle{
                                    anchors.verticalCenter: parent.verticalCenter
                                    width: 20
                                    height: 15
                                    color: "transparent"
                                    border.color: "black"
                                    Rectangle{
                                        width: 10
                                        height: 8
                                        color: outondisplaytime.checked?"green":"transparent"
                                        anchors.centerIn: parent
                                    }
                                    }
                                }//checkbox 2
                            }
                        }

                    } //end GroupBox 1
                    GroupBox{
                        Layout.row: 2
                        title: "sending configuration"
                        Layout.preferredWidth: 240
                        GridLayout{
                            columns: 2
                            rows:2
                            Row{
                                Layout.preferredHeight: fiexHeight
                                //这个按钮组可以不使用
                                ButtonGroup{
                                    id:sendradiogroup
                                }
                                RadioButton{
                                    id:id_sendascii
                                    text: "ASCII"
                                    checked: true
                                    implicitHeight: 25
                                    Layout.preferredHeight: fiexHeight
                                }
                                RadioButton{
                                    id:id_sendhex
                                    text: "Hex"
                                    checked: false
                                    implicitHeight: 25
                                    Layout.preferredHeight: fiexHeight
                                }
                            }//end row

                            Column{
                              Layout.row: 1
                              CheckBox{
                                id:inonwline
                                text: "auto repeat  "
                                checked: true
                                indicator: Rectangle{
                                    anchors.verticalCenter: parent.verticalCenter
                                    width: 20
                                    height: 15
                                    color: "transparent"
                                    border.color: "black"
                                    Rectangle{
                                        width: 10
                                        height: 8
                                        color: outonwline.checked?"green":"transparent"
                                        anchors.centerIn: parent
                                    }
                                    }
                                }//checkbox 1

                            }
                            RowLayout{
                                Layout.columnSpan: 1
                                Layout.preferredHeight: fiexHeight
                                TextField{
                                    id:sendinputField
                                    Layout.preferredHeight: 30
                                    Layout.preferredWidth: 60
                                    validator: IntValidator{}
                                    text: "1000"
                                }
                                Label{
                                    text:"ms"
                                }
                            }
                        }
                    } //end GroupBox 2

                } //end GridLayout
            }// end ColumnLayout left area

        ColumnLayout{
            Layout.fillHeight: true
            Layout.fillWidth: true
            ScrollView{
                Layout.fillHeight: true
                Layout.fillWidth: true
                background: Rectangle{
                    color: "transparent"
                    border.color: "black"
                    border.width: 2
                    radius: 5
                    Layout.fillHeight: true
                    Layout.fillWidth: true
                }
                //滚动条控件包裹TextArea
                TextArea{
                    id:rcvmsgtxtField
                    Layout.fillHeight: true
                    Layout.fillWidth: true
                }
            }
            GroupBox{
                Layout.preferredHeight: 100
                Layout.fillWidth: true
                ScrollView{
                    Layout.fillHeight: true
                    Layout.fillWidth: true
                    //滚动条控件包裹TextArea
                    TextArea{
                        id:sendmsgtxtField
                        Layout.fillHeight: true
                        Layout.fillWidth: true
                    }
                }
            }


        } //end ColumnLayout right

        }

        RowLayout{
            Layout.preferredHeight: 50
            TextField{
                Layout.fillWidth: true
                placeholderText: qsTr("Input Message...")
            }
            Button{
                text: qsTr("send")
            }
        }


    }//end ColumnLayout

    //设置页脚
    footer:Item{
        width:parent.width
        height: 35
        RowLayout{
            //这里宽度高度都需要设置一下,只设置一个会挤到一起。
            height: parent.height
            width: parent.width
            Rectangle{
                Layout.fillWidth: true
                Label{
                    text: "Recvived Bytes: 0"
                }
            }
            Rectangle{
                Layout.fillWidth: true
                Label{
                    text: "send Bytes: 0"
                }
            }
            Rectangle{
                Layout.fillWidth: true
                Label{
                    text: "author : Only"
                    horizontalAlignment: Text.AlignRight
                }
            }
        }

    }
}

        

相关文章:

  • Ubuntu Live USB 如何使用
  • 《深度洞察:MySQL与Oracle中游标的性能分野》
  • 重新排序--区间问题--差分求频率,全开ll
  • 静态路由复习实验
  • MyBatis-Plus逆向工程
  • ORM框架
  • SQL Server安装后 SSMS 无法连接:身份验证模式错误
  • 可编辑36页PPT | “新基建”在数字化智慧高速公路中的支撑应用方案智慧高速解决方案智慧交通方案
  • 《C奥林匹斯宝典:基础篇 - 重载函数》
  • 机器人传感器系统---时间戳对齐
  • vue使用markdown-it-katex部分公式展示不正确 katex版本低
  • 深度学习--softmax回归
  • 基于TradingView和CTPBee的自动化期货交易系统实现
  • Saas产品性能优化实战
  • bluecode-字符替换与最长子串问题
  • 【开题报告+论文+源码】基于SpringBoot+Vue的乡村公共资源管理系统
  • VS Code查看html格式文件插件:Live Server、HTML Preview
  • 多个SVN版本库,共用同一个和密码配置文件
  • Nacos 配置信息的发布流程是怎样的?服务端是如何校验和处理这些信息的?
  • 什么是SAQ评级?SAQ评级的好处?SAQ评级的意义
  • “朱雀玄武敕令”改名“周乔治华盛顿”?警方称未通过审核
  • 雷军内部演讲回应质疑:在不服输、打不倒方面,没人比我们更有耐心
  • 车建兴被留置:跌落的前常州首富和红星系重整迷路
  • 证监会发布《上市公司募集资金监管规则》,6月15日起施行
  • 由我国牵头制定,适老化数字经济国际标准发布
  • 回望星河深处,唤醒文物记忆——读《发现武王墩》