2

I'm looking to change a number of QGIS settings with a python script. Whilst I can find references to some specific keys through various questions/answers on StackExchange, I can't find a method to actually look these up myself.

The question How do I access QGIS program settings programmatically? indicates that I need to go into the source code to look these up. However, I'm only a novice with this scripting stuff, and don't really know where to start or what to look for.

Can you provide a generalised set of steps for finding these keys in the source code?

2
  • Your question is broad, what specific setting are you interested in? See, docs.qgis.org/2.14/en/docs/pyqgis_developer_cookbook/…
    – artwork21
    Dec 18, 2017 at 21:17
  • @artwork21 Right now I'm interested in toggling "Auto Open Form". However, what I'm really after is a method for answering this question myself (if that makes sense). Then I won't have to post another question on SE the next time I want to find a key. Dec 18, 2017 at 21:50

1 Answer 1

2

You can use the QSettings::allKeys() method by first importing it:

from PyQt4.QtCore import QSettings

Then

  • To get a list of current keys:

    QSettings().allKeys()
    
  • To print all keys individually (for readability):

    for keys in QSettings().allKeys():
        print keys
    
  • To search for a specific key:

    for keys in QSettings().allKeys():
        if 'Qgis' in keys:
            print keys
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.