qml - 自定义 Controls 2 SpinBox 时出错
问题描述
自定义 QtQuickControls2 SpinBox 时,我在关闭应用程序时在控制台中收到此错误:
“在引擎销毁时,仍有“2”项正在创建过程中。”
该数字根据窗口中的 Spinbox 数量而有所不同,每个自定义的指标都会上升(每个自定义 SpinBox 两次:一个用于向上指示器,一个用于向下指示器)。我尝试注释掉我的自定义代码的每一部分,以及使用此处提供的示例代码,所以我很肯定这就是错误的来源。
有谁知道如何摆脱这个错误?
主窗口代码:
import QtQuick 2.7
import QtQuick.Controls 2.3
ApplicationWindow{
width: 1600
height: 900
visible: true
SpinBox_custom{
}
}
自定义 SpinBox_custom 代码:
import QtQuick 2.11
import QtQuick.Controls 2.4
SpinBox {
id: control
value: 50
editable: true
contentItem: TextInput {
anchors.fill: parent
anchors.rightMargin : up.indicator.width
anchors.leftMargin : down.indicator.width
z: 2
text: control.textFromValue(control.value, control.locale)
font.pointSize: Style.textPointSize-2
color: '#7e8d9e'
selectionColor: '#7e8d9e'
selectedTextColor: "white"
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
readOnly: !control.editable
validator: control.validator
inputMethodHints: Qt.ImhFormattedNumbersOnly
}
up.indicator: Rectangle {
x: control.mirrored ? 0 : parent.width - width
height: parent.height
implicitWidth: 20
implicitHeight: 30
color: control.up.pressed ? '#dee2e6' : '#bec6ce'
border.color: enabled ? '#bec6ce' : '#dee2e6'
Text {
text: "+"
font.pixelSize: control.font.pixelSize * 2
color: '#428AC9'
anchors.fill: parent
fontSizeMode: Text.Fit
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}
down.indicator: Rectangle {
x: control.mirrored ? parent.width - width : 0
height: parent.height
implicitWidth: 20
implicitHeight: 30
color: control.down.pressed ? '#dee2e6' : '#bec6ce'
border.color: enabled ? '#bec6ce' : '#dee2e6'
Text {
text: "-"
font.pixelSize: control.font.pixelSize * 2
color: '#428AC9'
anchors.fill: parent
fontSizeMode: Text.Fit
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}
background: Rectangle {
implicitWidth: 90
}
}
解决方案
推荐阅读
- javascript - 将 prop 传递给另一个组件并在视图上渲染
- python - 在 for 循环的情况下使用 try/catch 块的正确方法是什么?
- python - 根据 csv 文件中的坐标从图像中裁剪片段
- python - 如何修复“AttributeError:未知属性 figsize”?
- ibm-cloud - IBM Cloud 用户管理 API - 邀请用户 - 用户状态未变为活动
- c# - 如何在一个表中选择具有两列匹配值的记录?
- android - 如何在 Windows 上使用 Python for Android 将 .py 转换为 APK 文件?
- android - android.database.sqlite.SQLiteException:没有这样的表:用户(代码1):使用android和sqlite
- oracle - 需要帮助来创建循环执行的清除操作
- c# - 如何使用实体框架连接三个表来获取所有数据