qt - QML 桌面中的单选按钮

标签 qt radio-button desktop qml

我的页面中有 3 个单选按钮,QML 桌面应用程序。一旦我检查了一个 - 我希望所有其他都未选中。
我尝试使用 CheckableGroup使用我在帮助中找到的代码:

CheckableGroup { id: group }
Row {
 id: row
 spacing: platformStyle.paddingMedium
 RadioButton {
     id: button1
     text: "1"
     platformExclusiveGroup: group
 }
 RadioButton {
     id: button2
     text: "2"
     platformExclusiveGroup: group
 }
 RadioButton {
     id: button3
     text: "3"
     platformExclusiveGroup: group
     checked: true
 }
}
但我收到错误“platformExclusiveGroup 不是有效的属性名称”
我尝试了另一种解决方案
RadioButton {
  id: rbtnDecimal1
  width: 130
  onClicked: {
    if (checked) {
      rbtnHexadecimal1.checked=false;
      rbtnString1.checked=false;
    }
  }
  text: "Decimal Data";
  anchors.left: rbtnHexadecimal1.right
}
当一个按钮被选中时,所有其他按钮都未选中,但其他按钮保持选中状态,直到我将鼠标移到它们上 - 它们变得未选中。
知道如何实现吗?

最佳答案

您需要指定 ExclusiveGroup 对于RadioButton s。

Row {
    id: row
    ExclusiveGroup { id: group }
    RadioButton {
        id: button1
        text: "1"
        exclusiveGroup: group
    }
    RadioButton {
        id: button2
        text: "2"
        exclusiveGroup: group
    }
    RadioButton {
        id: button3
        text: "3"
        exclusiveGroup: group
        checked: true
    }
}

关于qt - QML 桌面中的单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13450829/

相关文章:

qt - 使用 Qt 在 Windows 中查找特殊文件夹列表

c++ - QTableWidget 中的 SelectedRows 列表

qt - 在Mac OS下如何将最新版本的GCC(4.6)与Qt一起使用?

javascript - 将 onclick 事件添加到 jquery 中的单选按钮

android - 启动 Desktop main 时出现 libgdx ClassNotFoundException - Mac、IntelliJ

c++ - QGraphicsWidget 的上下文菜单事件

javascript - 如何使用链接提交表单字段值?

java - 从数据库中检索数据并用单选按钮显示它,单选按钮包含 struts 1.2 中的数据值

c# - 从 C# 应用程序调用 ASP.net Web 服务

permissions - Inno Setup 在所有用户的所有桌面上创建单独的快捷方式