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?

artwork21
35.2k8 gold badges69 silver badges135 bronze badges
asked Dec 18, 2017 at 16:08
2
  • Your question is broad, what specific setting are you interested in? See, docs.qgis.org/2.14/en/docs/pyqgis_developer_cookbook/… Commented 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. Commented 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
    
answered Dec 19, 2017 at 11:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.