5

Is there a keyboard shortcut, or even something like a toolbar button, which would make it easier and quicker to open (and close) the layers panel in QGIS (2.6).

I don't see one listed under the keyboard shortcuts list.

3 Answers 3

10

It's not built in (yet. I might just put it on my todo xmas list) however you can use some Python to do this:

from PyQt4.QtCore import *
from PyQt4.QtGui import *

dock = iface.mainWindow().findChild(QDockWidget, "Layers")

def activated():
    visible = dock.isVisible()
    dock.setVisible(not visible)

short = QShortcut(QKeySequence(Qt.ALT + Qt.Key_1), iface.mainWindow())
short.setContext(Qt.ApplicationShortcut)
short.activated.connect(activated)

To have this always on you can add it to .qgis2\python\setup.py and it will be run each time QGIS starts.

Here is some code you can add to your startup.py in order to control bindings

from functools import partial
from qgis.utils import iface

from PyQt4.QtCore import *
from PyQt4.QtGui import *

mappings = {"Layers": Qt.ALT + Qt.Key_1,
            "Browser": Qt.ALT + Qt.Key_2,
            "PythonConsole": Qt.ALT + Qt.Key_3}
shortcuts = []

def activated(dock):
    dock = iface.mainWindow().findChild(QDockWidget, dock)
    visible = dock.isVisible()
    dock.setVisible(not visible)

def bind():
    for dock, keys in mappings.iteritems():
        short = QShortcut(QKeySequence(keys), iface.mainWindow())
        short.setContext(Qt.ApplicationShortcut)
        short.activated.connect(partial(activated, dock))
        shortcuts.append(short)

bind()

This will take all the mappings and create shortcuts for them. Nifty!

9
  • +1 from me for the code, but I don't see any reaction using the shortcut on QGIS 2.6.1 standalone. Does it need the dev version?
    – AndreJ
    Commented Dec 18, 2014 at 6:49
  • No it should work in all versions.
    – Nathan W
    Commented Dec 18, 2014 at 10:39
  • Thanks for the update, but it is still not working. QGIS 2.6.1 on Windows XP and 7.
    – AndreJ
    Commented Dec 19, 2014 at 5:10
  • No errors at all?
    – Nathan W
    Commented Dec 19, 2014 at 5:18
  • No. The first one runs at least inside the python console editor (but not on startup), the second complaints there about unexpected intendin line 1.
    – AndreJ
    Commented Dec 19, 2014 at 6:42
4

If you're using Ubuntu, the commands found in the QGIS menu are accessible via heads-up-display (HUD).

To show / hide the layers panel, or the browser panel for example:

  • click the ALT key
  • then type 'layers'
  • then click ENTER.

enter image description here

The layers panel will show/hide

Similarily, you can access any tool that can be accessed from the menu panel of QGIS, such as the buffer tool, and the MMQGIS buffer tool:

enter image description here

1
  • 1
    Thanks - personally here I'm on Windows - but I'm sure others will find this useful. Commented Dec 17, 2014 at 17:34
3

I have not come across such a shortcut, but rightclicking on an empty part of the toolbar area lets you easily activate or deactivate panels and toolbars.

I guess it would not be too difficult to write a python plugin with its own icon for your task.

2
  • Your solution is definitely better than going through the full menu dialogue, thank you. Commented Dec 17, 2014 at 13:58
  • Note that a double-click on the top of the panel also moves the panel from/to being docked in the main window. I'm sure this is obvious to many, but it's a new discovery to me. Commented Dec 19, 2014 at 17:02

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.