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. How to save current index of ComboBox for supported map types
Forum Updated to NodeBB v4.3 + New Features

How to save current index of ComboBox for supported map types

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 423 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.
  • edipE Offline
    edipE Offline
    edip
    wrote on last edited by
    #1

    I try to save index of ComboBox for choosing supported map types of Open Street Map. When opening the app again, the last chosen map index should be displayed. Qt.labs.settings didn't work as the example below:

    import QtQuick 2.6
    import QtQuick.Controls 2.0
    import QtLocation 5.12
    import QtPositioning 5.12
    import Qt.labs.settings 1.0
    
    ApplicationWindow{
        id: root
        width: 500
        height: 500
        visible: true
        Settings{
                id:mycombo
                property alias maptype: selectmap.currentIndex
            }
        Flickable {
            height: parent.height
            width: parent.width
            clip: true
            contentHeight: Math.max(mapColumn.implicitHeight, height)
            Column{
                anchors.horizontalCenter: parent.horizontalCenter
                id:mapColumn
                spacing: 5
                anchors.fill : parent
                Row{
                    anchors.horizontalCenter: parent.horizontalCenter
                    spacing:25
                    Rectangle{
                    	width:mapColumn.width
                    	height:mapColumn.height-80
                    	Map {
                              id:map
                        	    anchors.fill: parent
                        	    plugin: Plugin {
                                  name: "osm"
                              }
                          }
                   }
              }
    
              Column{
                  id: combos
                  spacing: 10
                  width: parent.width
                  anchors.verticalCenter: root.verticalCenter
                      Row{
                          anchors.horizontalCenter: parent.horizontalCenter
                          spacing:1
                          Label{ text:"Map Type: "; height: selectmap.height; verticalAlignment: Text.AlignVCenter; }
                          // Map Types
                          ComboBox {
                              id: selectmap
                              width: 200
                              model:map.supportedMapTypes
                              textRole:"description"
                              onCurrentIndexChanged: map.activeMapType = map.supportedMapTypes[currentIndex]
    
                          }
                      }
              }
          }
        }
    }
    

    Is it possible to save the current index of ComboBox for maps?

    ODБOïO 1 Reply Last reply
    0
    • edipE edip

      I try to save index of ComboBox for choosing supported map types of Open Street Map. When opening the app again, the last chosen map index should be displayed. Qt.labs.settings didn't work as the example below:

      import QtQuick 2.6
      import QtQuick.Controls 2.0
      import QtLocation 5.12
      import QtPositioning 5.12
      import Qt.labs.settings 1.0
      
      ApplicationWindow{
          id: root
          width: 500
          height: 500
          visible: true
          Settings{
                  id:mycombo
                  property alias maptype: selectmap.currentIndex
              }
          Flickable {
              height: parent.height
              width: parent.width
              clip: true
              contentHeight: Math.max(mapColumn.implicitHeight, height)
              Column{
                  anchors.horizontalCenter: parent.horizontalCenter
                  id:mapColumn
                  spacing: 5
                  anchors.fill : parent
                  Row{
                      anchors.horizontalCenter: parent.horizontalCenter
                      spacing:25
                      Rectangle{
                      	width:mapColumn.width
                      	height:mapColumn.height-80
                      	Map {
                                id:map
                          	    anchors.fill: parent
                          	    plugin: Plugin {
                                    name: "osm"
                                }
                            }
                     }
                }
      
                Column{
                    id: combos
                    spacing: 10
                    width: parent.width
                    anchors.verticalCenter: root.verticalCenter
                        Row{
                            anchors.horizontalCenter: parent.horizontalCenter
                            spacing:1
                            Label{ text:"Map Type: "; height: selectmap.height; verticalAlignment: Text.AlignVCenter; }
                            // Map Types
                            ComboBox {
                                id: selectmap
                                width: 200
                                model:map.supportedMapTypes
                                textRole:"description"
                                onCurrentIndexChanged: map.activeMapType = map.supportedMapTypes[currentIndex]
      
                            }
                        }
                }
            }
          }
      }
      

      Is it possible to save the current index of ComboBox for maps?

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      @edip hi,
      After some manipulations i figured out that Settings works correctly but currentIndex of the combobox is resetted after the model change.

      So do like this

          Settings{
              id:mycomboSettings
              property int maptype
          }
      ...
            ComboBox {
      
                               onModelChanged: currentIndex = mycomboSettings.maptype
                              Component.onDestruction: mycomboSettings.maptype = currentIndex
      
                          }
      
      

      just make sure you provide application name, organization and domain. See here

      1 Reply Last reply
      1
      • edipE Offline
        edipE Offline
        edip
        wrote on last edited by
        #3

        Thank you @LeLev I found a solution before but your solution is much better.

        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