Skip to main content
replaced http://gis.stackexchange.com/ with https://gis.stackexchange.com/
Source Link

EDIT: This works on QGIS 2.12.1 from osgeo4w (Windows 8.1), but does not work on QGIS 2.12.1 from macports (OSX 10.11).

It appears that QT.Alt no longer works in QGIS 2.12. The correct reference is QT.Key_Alt. Enlightened by the link to the QT Key reference in this answeranswer.

The code below works with QGIS 2.12.1

from functools import partial
from qgis.utils import iface

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

mappings = {"Layers": Qt.Key_Alt + Qt.Key_1,
            "Browser": Qt.Key_Alt + Qt.Key_2}
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()

EDIT: This works on QGIS 2.12.1 from osgeo4w (Windows 8.1), but does not work on QGIS 2.12.1 from macports (OSX 10.11).

It appears that QT.Alt no longer works in QGIS 2.12. The correct reference is QT.Key_Alt. Enlightened by the link to the QT Key reference in this answer.

The code below works with QGIS 2.12.1

from functools import partial
from qgis.utils import iface

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

mappings = {"Layers": Qt.Key_Alt + Qt.Key_1,
            "Browser": Qt.Key_Alt + Qt.Key_2}
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()

EDIT: This works on QGIS 2.12.1 from osgeo4w (Windows 8.1), but does not work on QGIS 2.12.1 from macports (OSX 10.11).

It appears that QT.Alt no longer works in QGIS 2.12. The correct reference is QT.Key_Alt. Enlightened by the link to the QT Key reference in this answer.

The code below works with QGIS 2.12.1

from functools import partial
from qgis.utils import iface

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

mappings = {"Layers": Qt.Key_Alt + Qt.Key_1,
            "Browser": Qt.Key_Alt + Qt.Key_2}
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()
added 122 characters in body
Source Link
andrewg
  • 136
  • 6

EDIT: This works on QGIS 2.12.1 from osgeo4w (Windows 8.1), but does not work on QGIS 2.12.1 from macports (OSX 10.11).

It appears that QT.Alt no longer works in QGIS 2.12. The correct reference is QT.Key_Alt. Enlightened by the link to the QT Key reference in this answer.

The code below works with QGIS 2.12.1

from functools import partial
from qgis.utils import iface

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

mappings = {"Layers": Qt.Key_Alt + Qt.Key_1,
            "Browser": Qt.Key_Alt + Qt.Key_2}
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()

It appears that QT.Alt no longer works in QGIS 2.12. The correct reference is QT.Key_Alt. Enlightened by the link to the QT Key reference in this answer.

The code below works with QGIS 2.12.1

from functools import partial
from qgis.utils import iface

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

mappings = {"Layers": Qt.Key_Alt + Qt.Key_1,
            "Browser": Qt.Key_Alt + Qt.Key_2}
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()

EDIT: This works on QGIS 2.12.1 from osgeo4w (Windows 8.1), but does not work on QGIS 2.12.1 from macports (OSX 10.11).

It appears that QT.Alt no longer works in QGIS 2.12. The correct reference is QT.Key_Alt. Enlightened by the link to the QT Key reference in this answer.

The code below works with QGIS 2.12.1

from functools import partial
from qgis.utils import iface

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

mappings = {"Layers": Qt.Key_Alt + Qt.Key_1,
            "Browser": Qt.Key_Alt + Qt.Key_2}
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()
Source Link
andrewg
  • 136
  • 6

It appears that QT.Alt no longer works in QGIS 2.12. The correct reference is QT.Key_Alt. Enlightened by the link to the QT Key reference in this answer.

The code below works with QGIS 2.12.1

from functools import partial
from qgis.utils import iface

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

mappings = {"Layers": Qt.Key_Alt + Qt.Key_1,
            "Browser": Qt.Key_Alt + Qt.Key_2}
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()