qml绘制仪表盘控件

2023-11-03

刚开始上手qt,说实话迷得很啊。。。

不过qt做的界面是真的漂亮,之前在b站看qt官方发布的一些视频,仪表盘煞是好看

今天倒腾了一天,用qml绘制了一个简单的汽车仪表控件,趁现在还热着,先记下来

新建一个空的qml工程

创建工程的时候要注意,工程路径中不能有中文,否则会导致编译失败

创建完成后按例编译运行,确保工程能正常编译,否则等写得差不多却发现无法正常编译那就很尴尬了。。。

再添加一个单独的.qml文件,我们在里面编写自定义的控件,这样在别的工程中只要载入这个qml文件就能使用了~~

起个名字 (Mycar。。。哈哈,暂且就这样吧

暂时就以这个为例子吧,今天做出来的也就和这个像

从上面这张图中,我们可以看到这个表盘主要是由几个弧构成。qt官方这个例子是先通过Photoshop设计出表盘整体的样式,然后通过插件直接从ps中导出.qml,接着就是在qt软件上进行编辑。不得不说这种设计和逻辑分开的方式的确非常的棒!让天堂的归天堂,让尘土的归尘土。ps咱不熟悉,过qt的ps插件倒是挺有意思,具体的我还没有研究明白,等哪天搞懂了再写篇文章记一下。需要这个插件的朋友请往:https://code.qt.io/cgit/qt-labs/photoshop-qmlexporter.git/ 或者同性社区: https://github.com/qt-labs/photoshop-qmlexporter

因为这个仪表主要由弧构成,因此我们需要在canvas中对仪表的各个部分进行绘制。首先,我们需要绘制两个重叠的圆弧。最下面的圆弧设置成浅灰色作为背景,最顶上的圆弧则实时显示我们汽车的速度。刚刚创建的qml文件中,键入如下代码:

// file - Mycar.qml

import QtQuick 2.0

Item {
    id: carItem
    width: 100
    height: 100

    // 背景圆弧线宽
    property int btm_lineWidth: 15
    // 背景圆弧颜色
    property color btm_backgroundColor: Qt.rgba(0, 0, 0, 0.1);
    // 背景圆弧半径 开始角度 结束角度
    property int btm_r: 20
    property double btm_startAngle: 0
    property double btm_endAngle: 90

    onBtm_lineWidthChanged: canvas.requestPaint()
    onBtm_backgroundColorChanged: canvas.requestPaint()
    onBtm_rChanged: canvas.requestPaint()
    onBtm_startAngleChanged: canvas.requestPaint()
    onBtm_endAngleChanged: canvas.requestPaint()

    // 顶层圆弧线宽
    property int top_lineWidth: 10
    // 顶层圆弧颜色
    property color top_backgroundColor: "lightgreen"
    // 顶层圆弧半径 开始角度 结束角度
    property int top_r: 20
    property double top_startAngle: 0
    property double top_endAngle: 90

    onTop_lineWidthChanged: canvas.requestPaint()
    onTop_backgroundColorChanged: canvas.requestPaint()
    onTop_rChanged: canvas.requestPaint()
    onTop_startAngleChanged: canvas.requestPaint()
    onTop_endAngleChanged: canvas.requestPaint()

    Canvas {
        id: canvas
        width: carItem.width
        height: carItem.height

        onPaint: {
            var ctx = getContext("2d");
            ctx.clearRect(0, 0, canvas.width, canvas.height);

            // 画背景圆弧
            ctx.lineWidth = carItem.btm_lineWidth;
            ctx.strokeStyle = carItem.btm_backgroundColor;
            ctx.beginPath();
            ctx.arc(carItem.width/2, carItem.width/2, carItem.btm_r, (carItem.btm_startAngle/180*Math.PI), (carItem.btm_endAngle/180*Math.PI));
            ctx.stroke();


            // 画顶层圆弧
            ctx.lineWidth = carItem.top_lineWidth;
            ctx.strokeStyle = carItem.top_backgroundColor;
            ctx.beginPath();
            ctx.arc(carItem.width/2, carItem.width/2, carItem.top_r, (carItem.top_startAngle/180*Math.PI), (carItem.top_endAngle/180*Math.PI));
            ctx.stroke();
        }
    }
}

这里啰嗦一下,我顶层圆弧和底层圆弧属性的命名前置分别是“top_”、“btm_”。为了在设计模式中更改这些属性的值时,图像能够马上更新,代码中使用了形似 onXxxxxxChanged(格式:on<Property>Changed)的信号处理器,当某个属性的值变更时,会触发canvas的重绘(即,canvas.requestPaint())。举个栗子,例如代码中的btm_lineWidth变量,写法就是:

on + Btm_lineWidth + Changed     ,     即:onBtm_lineWidthChanged: canvas.requestPaint()

如果开头的b没有大写,就会报:

后面在main.qml中引用Mycar.qml的控件也是如此,调用的对象名称首字母必须大写。详见qt文档:https://doc.qt.io/qt-5/qtqml-documents-definetypes.html

接着,回到main.qml文件中,引用我们刚刚写的仪表控件

点击左侧的 设计,可以看到自定义的仪表控件已经被载入到界面中。右下角的则是我们在Mycar.qml中定义的,我们可以通过修改这些达到更改顶层和底层圆弧的大小、颜色等目的

接下来,调整一下仪表的位置和大小,这里我还增加了一些控件,一个开关用来控制顶层圆弧的线宽,滑块用来模拟汽车的速度,文本框用来显示速度。。。

在main.qml中给Mycar一个id=speed_car,然后将顶层圆弧的终止角度与滑块进行绑定。当然你可以使用下图的方式进行绑定,也可以直接在Mycar中进行书写。这里我们约定这个速度仪表盘的最大刻度为200Km/h,将0~200Km/h映射到我们的仪表盘上。

点击左下角的运行,滑动滑块,可以看到开关控制的两种效果

不过作为仪表盘来说,虽然现在有了点模样,但还缺少了刻度盘。qt官方的刻度盘是ps设计好的,之后再在qt中把速度的值用文本框加上,这样就能设置字体和样式了。这里咱没有ps,不过没关系啊,用代码画出来就行,撸起袖子就是干

回到Mycar.qml文件中,将绘制刻度盘的代码加上

import QtQuick 2.0

Item {
    id: carItem
    width: 100
    height: 100

    // 背景圆弧线宽
    property int btm_lineWidth: 15
    // 背景圆弧颜色
    property color btm_backgroundColor: Qt.rgba(0, 0, 0, 0.1);
    // 背景圆弧半径 开始角度 结束角度
    property int btm_r: 20
    property double btm_startAngle: 0
    property double btm_endAngle: 90

    onBtm_lineWidthChanged: canvas.requestPaint()
    onBtm_backgroundColorChanged: canvas.requestPaint()
    onBtm_rChanged: canvas.requestPaint()
    onBtm_startAngleChanged: canvas.requestPaint()
    onBtm_endAngleChanged: canvas.requestPaint()

    // 顶层圆弧线宽
    property int top_lineWidth: 10
    // 顶层圆弧颜色
    property color top_backgroundColor: "lightgreen"
    // 顶层圆弧半径 开始角度 结束角度
    property int top_r: 20
    property double top_startAngle: 0
    property double top_endAngle: 90

    onTop_lineWidthChanged: canvas.requestPaint()
    onTop_backgroundColorChanged: canvas.requestPaint()
    onTop_rChanged: canvas.requestPaint()
    onTop_startAngleChanged: canvas.requestPaint()
    onTop_endAngleChanged: canvas.requestPaint()

    // 刻度盘
    property color dial_color: "#000000"
    property int dial_lineWidth: 3
    property int dial_addR: 2          // 通过调整该变量可以控制刻度盘圆弧与底层圆弧的距离
    property int dial_longNum: 5       // 刻度盘长刻度线的数量
    property int dial_longLen: 10      // 刻度盘长刻度线的长度

    onDial_colorChanged: canvas.requestPaint()
    onDial_lineWidthChanged: canvas.requestPaint()
    onDial_addRChanged: canvas.requestPaint()
    onDial_longNumChanged: canvas.requestPaint()
    onDial_longLenChanged: canvas.requestPaint()

    Canvas {
        id: canvas
        width: carItem.width
        height: carItem.height

        onPaint: {
            var ctx = getContext("2d");
            ctx.clearRect(0, 0, canvas.width, canvas.height);

            // 画背景圆弧
            ctx.lineWidth = carItem.btm_lineWidth;
            ctx.strokeStyle = carItem.btm_backgroundColor;
            ctx.beginPath();
            ctx.arc(carItem.width/2, carItem.width/2, carItem.btm_r, (carItem.btm_startAngle/180*Math.PI), (carItem.btm_endAngle/180*Math.PI));
            ctx.stroke();

            // 画大刻度盘
            ctx.lineWidth = carItem.dial_lineWidth;
            ctx.strokeStyle = carItem.dial_color;
            ctx.beginPath();
            ctx.arc(carItem.width/2, carItem.width/2, carItem.btm_r+carItem.btm_lineWidth+carItem.dial_addR, (carItem.btm_startAngle/180*Math.PI), (carItem.btm_endAngle/180*Math.PI));
            var tmp_step = (carItem.btm_endAngle-carItem.btm_startAngle)/carItem.dial_longNum;
            for(var i=carItem.btm_startAngle;i<carItem.btm_endAngle+tmp_step;i+=tmp_step) {
                var tmp_x = (carItem.width/2)+(carItem.btm_r+carItem.btm_lineWidth+carItem.dial_addR)*Math.cos(i/180*Math.PI);
                var tmp_y = (carItem.width/2)+(carItem.btm_r+carItem.btm_lineWidth+carItem.dial_addR)*Math.sin(i/180*Math.PI);
                ctx.moveTo(tmp_x, tmp_y);
                // 绘制长刻度线
                ctx.lineTo(tmp_x+carItem.dial_longLen*Math.cos(i/180*Math.PI), tmp_y+(carItem.dial_longLen*Math.sin(i/180*Math.PI)));
            }
            ctx.stroke();

            // 画顶层圆弧
            ctx.lineWidth = carItem.top_lineWidth;
            ctx.strokeStyle = carItem.top_backgroundColor;
            ctx.beginPath();
            ctx.arc(carItem.width/2, carItem.width/2, carItem.top_r, (carItem.top_startAngle/180*Math.PI), (carItem.top_endAngle/180*Math.PI));
            ctx.stroke();
        }
    }
}

调整刻度盘的参数,嘿嘿,还是有点模样的

接着用标签控件将速度刻度加上

运行效果:

工程完整代码如下:

main.qml

// file - main.qml

import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Controls 2.0

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello qt")

    Mycar {
        id: speed_car
        x: 175
        y: 93
        width: 291
        height: 238
        dial_addR: -6
        dial_longNum: 10
        dial_longLen: 15
        dial_lineWidth: 3
        btm_lineWidth: 22
        top_lineWidth: 10
        top_endAngle: slider.value*1.3+140
        top_startAngle: 140
        btm_endAngle: 400
        btm_startAngle: 140
        btm_r: 120
        top_r: 120

        Text {
            id: speed
            x: 104
            y: 116
            width: 89
            height: 44
            text: slider.value
            style: Text.Normal
            font.weight: Font.ExtraBold
            font.capitalization: Font.MixedCase
            font.pixelSize: 40
            font.bold: true
            font.family: "Verdana"
            horizontalAlignment: Text.AlignHCenter
                }

        Label {
            id: speed_label
            x: 131
            y: 154
            width: 45
            height: 30
            text: qsTr("Km/h")
            font.pointSize: 11
            font.bold: true
            verticalAlignment: Text.AlignBottom
        }

        Label {
            id: label1
            x: 8
            y: 235
            width: 23
            height: 25
            text: qsTr("0")
            font.weight: Font.Normal
            horizontalAlignment: Text.AlignHCenter
            font.pointSize: 14
        }

        Label {
            id: label2
            x: 263
            y: 235
            width: 33
            height: 25
            text: qsTr("200")
            horizontalAlignment: Text.AlignHCenter
            font.pointSize: 14
            font.weight: Font.Normal
        }

        Label {
            id: label3
            x: -28
            y: 172
            width: 23
            height: 25
            text: qsTr("20")
            horizontalAlignment: Text.AlignHCenter
            font.pointSize: 14
            font.weight: Font.Normal
        }
    }

    Switch {
        id: sth
        x: 501
        y: 10
        text: "Wifi"

        onClicked: {
            if(sth.position) {
                speed_car.top_lineWidth = speed_car.btm_lineWidth;
            } else {
                speed_car.top_lineWidth = 10
            }
        }
    }

    Slider {
        id: slider
        x: 220
        y: 367
        font.pointSize: 14
        stepSize: 1
        to: 200
        from: 0
        value: 0

        onValueChanged: {
            if(value<60) {
                speed.color = "black"
            }
            else if(value<120) {
                speed.color = "#f2ac28"
            }
            else {
                speed.color = "red"
            }
            speed_label.color = speed.color
        }
    }

    Label {
        id: label4
        x: 466
        y: 264
        width: 42
        height: 25
        text: qsTr("180")
        horizontalAlignment: Text.AlignHCenter
        font.pointSize: 14
        font.weight: Font.Normal
    }

    Label {
        id: label5
        x: 146
        y: 192
        width: 23
        height: 25
        text: qsTr("40")
        horizontalAlignment: Text.AlignHCenter
        font.pointSize: 14
        font.weight: Font.Normal
    }

    Label {
        id: label6
        x: 476
        y: 192
        width: 23
        height: 25
        text: qsTr("160")
        horizontalAlignment: Text.AlignHCenter
        font.pointSize: 14
        font.weight: Font.Normal
    }

    Label {
        id: label7
        x: 172
        y: 123
        width: 23
        height: 25
        text: qsTr("60")
        horizontalAlignment: Text.AlignHCenter
        font.pointSize: 14
        font.weight: Font.Normal
    }

    Label {
        id: label8
        x: 445
        y: 123
        width: 35
        height: 25
        text: qsTr("140")
        horizontalAlignment: Text.AlignHCenter
        font.pointSize: 14
        font.weight: Font.Normal
    }

    Label {
        id: label9
        x: 236
        y: 73
        width: 23
        height: 25
        text: qsTr("80")
        horizontalAlignment: Text.AlignHCenter
        font.pointSize: 14
        font.weight: Font.Normal
    }

    Label {
        id: label10
        x: 382
        y: 72
        width: 36
        height: 25
        text: qsTr("120")
        horizontalAlignment: Text.AlignHCenter
        font.pointSize: 14
        font.weight: Font.Normal
    }

    Label {
        id: label11
        x: 310
        y: 62
        width: 23
        height: 25
        text: qsTr("100")
        horizontalAlignment: Text.AlignHCenter
        font.pointSize: 14
        font.weight: Font.Normal
    }

}

Mycar.qml

// file - Mycar.qml

import QtQuick 2.0

Item {
    id: carItem
    width: 100
    height: 100

    // 背景圆弧线宽
    property int btm_lineWidth: 15
    // 背景圆弧颜色
    property color btm_backgroundColor: Qt.rgba(0, 0, 0, 0.1);
    // 背景圆弧半径 开始角度 结束角度
    property int btm_r: 20
    property double btm_startAngle: 0
    property double btm_endAngle: 90

    onBtm_lineWidthChanged: canvas.requestPaint()
    onBtm_backgroundColorChanged: canvas.requestPaint()
    onBtm_rChanged: canvas.requestPaint()
    onBtm_startAngleChanged: canvas.requestPaint()
    onBtm_endAngleChanged: canvas.requestPaint()

    // 顶层圆弧线宽
    property int top_lineWidth: 10
    // 顶层圆弧颜色
    property color top_backgroundColor: "lightgreen"
    // 顶层圆弧半径 开始角度 结束角度
    property int top_r: 20
    property double top_startAngle: 0
    property double top_endAngle: 90

    onTop_lineWidthChanged: canvas.requestPaint()
    onTop_backgroundColorChanged: canvas.requestPaint()
    onTop_rChanged: canvas.requestPaint()
    onTop_startAngleChanged: canvas.requestPaint()
    onTop_endAngleChanged: canvas.requestPaint()

    // 刻度盘
    property color dial_color: "#000000"
    property int dial_lineWidth: 3
    property int dial_addR: 2          // 通过调整该变量可以控制刻度盘圆弧与底层圆弧的距离
    property int dial_longNum: 5       // 刻度盘长刻度线的数量
    property int dial_longLen: 10      // 刻度盘长刻度线的长度

    onDial_colorChanged: canvas.requestPaint()
    onDial_lineWidthChanged: canvas.requestPaint()
    onDial_addRChanged: canvas.requestPaint()
    onDial_longNumChanged: canvas.requestPaint()
    onDial_longLenChanged: canvas.requestPaint()

    Canvas {
        id: canvas
        width: carItem.width
        height: carItem.height

        onPaint: {
            var ctx = getContext("2d");
            ctx.clearRect(0, 0, canvas.width, canvas.height);

            // 画背景圆弧
            ctx.lineWidth = carItem.btm_lineWidth;
            ctx.strokeStyle = carItem.btm_backgroundColor;
            ctx.beginPath();
            ctx.arc(carItem.width/2, carItem.width/2, carItem.btm_r, (carItem.btm_startAngle/180*Math.PI), (carItem.btm_endAngle/180*Math.PI));
            ctx.stroke();

            // 画大刻度盘
            ctx.lineWidth = carItem.dial_lineWidth;
            ctx.strokeStyle = carItem.dial_color;
            ctx.beginPath();
            ctx.arc(carItem.width/2, carItem.width/2, carItem.btm_r+carItem.btm_lineWidth+carItem.dial_addR, (carItem.btm_startAngle/180*Math.PI), (carItem.btm_endAngle/180*Math.PI));
            var tmp_step = (carItem.btm_endAngle-carItem.btm_startAngle)/carItem.dial_longNum;
            for(var i=carItem.btm_startAngle;i<carItem.btm_endAngle+tmp_step;i+=tmp_step) {
                var tmp_x = (carItem.width/2)+(carItem.btm_r+carItem.btm_lineWidth+carItem.dial_addR)*Math.cos(i/180*Math.PI);
                var tmp_y = (carItem.width/2)+(carItem.btm_r+carItem.btm_lineWidth+carItem.dial_addR)*Math.sin(i/180*Math.PI);
                ctx.moveTo(tmp_x, tmp_y);
                // 绘制长刻度线
                ctx.lineTo(tmp_x+carItem.dial_longLen*Math.cos(i/180*Math.PI), tmp_y+(carItem.dial_longLen*Math.sin(i/180*Math.PI)));
            }
            ctx.stroke();

            // 画顶层圆弧
            ctx.lineWidth = carItem.top_lineWidth;
            ctx.strokeStyle = carItem.top_backgroundColor;
            ctx.beginPath();
            ctx.arc(carItem.width/2, carItem.width/2, carItem.top_r, (carItem.top_startAngle/180*Math.PI), (carItem.top_endAngle/180*Math.PI));
            ctx.stroke();
        }
    }
}

工程包:https://download.csdn.net/download/t01051/12654094

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

qml绘制仪表盘控件 的相关文章

  • Qt 的 sysroot 和前缀选项的实际示例是什么

    我正在查看可以运行的所有选项configureQt 提供的脚本 特别是 qt everywhere opensource src 5 2 0 经过大量搜索后 我确定这些东西充其量记录很少 所以我希望我能得到一些帮助 当我查看描述时prefi
  • 无法隐藏 QMenu 对象 QMenu::setVisible()?

    我已经建立了一个QMenu MainMenu在我的上面MainWindow在我的应用程序中 大家都习惯了 我有以下QMenu主菜单 文件 编辑 SuperHeavyExpertMenus 设置 帮助 我想隐藏子树SuperHeaverExp
  • 什么时候应该首选 Loader 而不是 createQmlObject,反之亦然 - QML?

    两者都可以动态创建对象 什么时候应该Loader优先于Qt createQmlObjectQML 中反之亦然吗 The Loader可以被视为特定对象的占位符 它还使您能够通过Loader s id Qt createQmlObject通常
  • 异步设计中如何知道哪个QNetworkReply属于QNetworkRequest?

    我可以轻松地用 C 进行异步设计 HttpResponseMessage response await httpClient GetAsync InputAddress Text run when request finished And
  • PySide2/QML 填充 Gridview 模型/委托并为其设置动画

    我是 QML 的新手 正在寻求以下几点帮助 如何基于 TextField 输入 如 Regex 通过 PySide2 过滤 Gridview 模型中的 QAbstractListModel 数据 标题 如何在鼠标悬停时为 Gridview
  • 在 Qt Creator 中相互公开 QML 组件

    我正在使用 Qt Quick 和 PySide2 开发仪表板应用程序 但在 Qt Creator 的设计模式中公开我的 QML 组件时遇到问题 我的文件夹结构如下所示 myapp mycomponents component1 qml co
  • 如何在 C++ 运行时更改 QML 对象的属性?

    我想在运行时更改 QML 对象的文本 我尝试如下 但文本仍然为空 这是后端类 class BackEnd public QObject Q OBJECT Q PROPERTY QString userFieldText READ userF
  • 如何在模型更改时停止ListView“跳跃”

    我需要做什么 我需要创建一个聊天窗口用一个ListView在 QML 中存储聊天消息 我设置listView positionViewAtEnd 以便跟踪最后的消息 我禁用positionViewAtEnd当我向上滚动时 我可以阅读过去的消
  • 使用 Visual Studio 2013 构建 Qt 5.2.1 的静态版本

    几天来我一直在尝试使用 Visual Studio 2013 构建 Qt 的静态版本 我就是不明白我做错了什么 System Windows 7 64 位 Visual Studio 2013 仍安装 Visual Studio 2012
  • 如何将枚举类传递给 QML?

    我正在学习QML with Qt并在通过时遇到一些麻烦enum class to qml 当我使用信号时int参数 一切正常 代码运行完美 But 麻烦就在这里 如果我使用信号与一些enum class我有参数undefinedqml 信号
  • 内容居中的流式布局

    我有一排项目 当窗口宽度变得太小而无法显示一行中的所有项目时 这些项目应该堆叠起来 如下图所示 The Flow组件堆叠项目 但它们不是居中而是在左侧或右侧对齐 Flow Item Item Item Item Item QML 中是否有内
  • 放大 QGraphicsView 时如何保持 QPen 像素宽度相同

    我编写了一个快速而令人讨厌的程序来帮助我可视化我正在从事的项目的一个方面 尽管我从 4 1 1 开始就开始使用 Qt 但我从未真正需要使用 QGraphics 模块 当我开始使用该程序时 我正在一台运行 Windows XP Qt4 7 0
  • 在另一个中使用 QAbstractListModel

    我在尝试使用 Qt QML 为我的应用程序开发数据模型时遇到问题 我已经用过一个QAbstractListModel能够将海关数据模型从 C 传递到 QML 并且它对于简单模型 例如基于字符串和布尔的模型 来说就像一个魅力 但现在我需要建立
  • 在 QML 中控制纹理 3D 对象的不透明度

    我对 QML 中的 Qt 3D 有点陌生 我正在尝试控制 Qt 3D 的不透明度textured3D 对象 我正在使用简单qml3d https github com tripolskypetr simpleqml3d测试项目来做到这一点
  • 如何为 qmlRegisterSingletonType 实现单例提供程序?

    我想在 QML 中使用 C 类作为 Singleton 实例 并认为我必须使用 qmlRegisterSingletonType 注册它们 此函数需要一个提供已注册 C 类的实例的函数 我在 Windows 上使用最新的 Qt 5 3 1
  • 打开和关闭附加窗口 (QML)

    目前我有一个通过以下方式打开的窗口 property variant win Button id testButton MouseArea onClicked var component Qt createComponent test qm
  • QML 中可重用的字体属性[重复]

    这个问题在这里已经有答案了 在 QML 中 我希望能够定义一组字体属性以进行简单的语义重用 例如 代替 Text text This is a header font family Encode Sans weight Font Black
  • 连接到 QNetworkReply::error 信号

    我正在使用 Qt5 的新连接语法 QNetworkReply 有一个名为error http qt project org doc qt 5 0 qtnetwork qnetworkreply html error 2还有一个函数叫做err
  • 为什么动态 qml 对象的创建如此缓慢,有哪些合理的替代方案?

    我想要实现的目标类似于棋盘游戏 有一个100 100的网格 放在一个Item它驻留在一个Flickable 游戏板 的各个矩形都是 svg 图像 目前大约有 20 种 可能会增加到数百种 作为基准测试 我只是尝试用元素填充 世界 Compo
  • PyQt5 使动态小部件可点击并将参数传递给另一个函数

    我正在尝试制作动态小部件并使它们可点击 通过单击一个小部件 它应该将动态值传递给其他小部件 我尝试过 sender 和其他访问小部件的选项 但没有任何效果 所有小部件都从最后一个小部件发送信息 下面是代码 import sys from P

随机推荐

  • 谷歌验单接口报projectNotLinked错误

    最近公司的一款安卓应用 用户购买商品后 服务端在调用谷歌接口进行验单的时候 谷歌接口会报projectNotLinked的错误 错误如下 error errors domain androidpublisher reason project
  • 对Flink集群进行远程调试

    导读 在学习或者使用各个大数据框架的时候 往往想对runtime层次的代码进行调试或者跟踪阅读 但其往往部署在其他机器上 因此需要进行远程调试 本文以Flink为例 介绍如何通过IDEA进行Flink的runtime层次的远程调试 环境 F
  • Ant Design Vue select下拉列表设置默认值

    在项目中需要为Ant Design Vue 的 select 组件设置一个默认值 如下图所示的状态下拉选择框 默认选择全部 代码如下 1
  • Linux--硬链接和软链接

    文件都有文件名与数据 这在 Linux 上被分成两个部分 用户数据 user data 与元数据 metadata 用户数据 即文件数据块 data block 数据块是记录文件真实内容的地方 而元数据则是文件的附加属性 如文件大小 创建时
  • Python常用第三方库——简介及下载地址

    Python常用第三方库 可以在 The Python Package Index PyPI 软件库 官网主页 https pypi org 查询 下载 和 发布 Python包或库 网络爬虫 requests https pypi org
  • 如何使用python来进行回归分析

    文章主要介绍两种常见的回归分析方法 以及其对应的Python实现操作 目录 什么是回归分析 为什么使用回归分析 回归分析技术有哪些 使用Python实现回归分析 什么是回归分析 在统计学中 回归分析 regression analysis
  • ​第10章 存储过程与存储函数​

    第10章存储过程与存储函数 10 1修改MySQL的结束符为 delimiter delimiter 10 2 创建一个不带参数的存储过程P str 输出 Hello MySQL 10 4 建立存储函数P math 如果 高等数学 课程的平
  • VUE element-ui之上传身份证照片正反面详细代码

    步骤 定义上传组件
  • 6年软件测试经历:成长、迷茫、奋斗

    前言 测试工作6年 经历过不同产品 共事过不同专业背景 能力的同事 踩过测试各种坑 遇到过各种bug 测试职场生涯积极努力上进业务和技术能力快速进步过 也有努力付出却一无所得过 有对测试生涯前景充满希望认为一片朝气蓬勃过 也有对中年危机思考
  • 英语——分享篇——每日100词——201-300

    chess che车 拼音 ss两个美女 编码 车里有两个美女在下国际象棋 April ap阿婆 拼音 ri日 拼音 l棍子 编码 四月份阿婆每日拿着棍子 palace place地方 这个地方是宫殿 bottle bo60 象形 ttle
  • 1分钟搭建swagger3好看实用接口文档

    这里写自定义目录标题 1分钟搭建swagger3好看实用接口文档 引入jar 包 直接copy 创建config文件 直接copy 启动访问 1分钟搭建swagger3好看实用接口文档 不废话 引入jar 包 直接copy
  • request entity too large

    1 分2中情况 1 带413 请求文件太大 不包含参数 413 Request Entity Too Large 2 不带413 请求实体太大 包含参数 文件等 客户端发送的实体主体部分比服务器能够或者希望处理的要大 request ent
  • Unity中的C#开发基础(1)

    主要记录一些和C 有区别的地方 1 把信息和反馈打印到控制台 1 Debug Log 2 Debug LogFormat Debug LogFormat Hello world add 0 and 1 firstNumber secondN
  • 安装nginx之后,处理 conf.d下无default.conf文件

    在学习nginx的过程中 安装nginx后找不到conf d目录下的default conf文件 其原因是该操作系统下的epel源是默认下载就是Fedora操作系统的 方案一 解决方法 重新进行安装nginx 并修改nginx的epel镜像
  • python实现n个学生的3门成绩总分排序,平均分

    直接上代码 解释在注释 不懂评论留言 必回 4 输入n个学生的3门成绩 分别计算n个学生的总分 每门功课的平均分 按学生的总分降序显示学生的信息 并输出每门功课的平均分 print 请输入一共多少个学生 end n int input 创建
  • Flutter 悬浮弹出效果

    最近在 Flutter 的使用中需要做一个悬浮弹窗的效果 通过查阅资料了解 Overlay 可以做出悬浮框的效果 但没有弹出效果 不符合我的预期 后来发现其实并不一定要真的悬浮 通过 showModalBouttonSheet方法和 Sta
  • JDBC的配置文件与工具类的封装

    package cn sxt login utils import java io IOException import java sql Connection import java sql DriverManager import ja
  • mybatis插入动态表名

    项目场景 项目中需要动态的选择插入的数据表名 但是在实际使用过程中总会遇到部分问题 问题描述 在xml中填写sql语句 由于表中含有月份信息 需要动态的选择表名 然而用 的方式传参 总是显示语句错误
  • 基于centOS7.5 x64/openjdk1.8/tomcat8.5/nginx1.16/nodejs/mysql8.0/redis3/git的服务器环境配置)

    基于centOS7 5 64 openjdk1 8 tomcat nginx nodejs mysql5 7 git的服务器环境配置 我以前的三年和未来的三年从事网站开发 主要手段是JAVA python nodejs 前端大套间 偶尔写写
  • qml绘制仪表盘控件

    刚开始上手qt 说实话迷得很啊 不过qt做的界面是真的漂亮 之前在b站看qt官方发布的一些视频 仪表盘煞是好看 今天倒腾了一天 用qml绘制了一个简单的汽车仪表控件 趁现在还热着 先记下来 新建一个空的qml工程 创建工程的时候要注意 工程