Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. The QML Settings property alias trick with a button group
Qt 6.11 is out! See what's new in the release blog

The QML Settings property alias trick with a button group

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 354 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rs___
    wrote on last edited by
    #1

    I'm able to easily created persist text field settings using

    Settings {
        property alias my_setting: my_setting_field.text
    }
    TextField {
        id: my_setting_field
    }
    

    I now need a setting that takes one of a set of possible values. I tried something like this

    Settings {
        property alias my_setting: my_setting_group.checkedButton._value
    }
    ButtonGroup { id: my_setting_group }
    Button {
        text: "option 1"
        property string _value: "option_1"
        checked: app_settings.my_setting === _value
        ButtonGroup.group: my_setting_group
    }
    Button {
        text: "option 2"
        property string _value: "option_2"
        checked: app_settings.my_setting === _value
        ButtonGroup.group: my_setting_group
    }
    

    and a few variations but couldn't get anything to work. Also, I would like a way to choose the default checked button when the app starts for the first time.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved