1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

QGIS Pythonコンソールでパネルの表示/非表示を操作する

Last updated at Posted at 2019-12-12

QGISのpythonプラグインからパネルの操作をしたい。
調べた。

参考にしたのは以下のやりとり。
https://gis.stackexchange.com/questions/317058/how-to-add-dockwidget-above-the-layer-panel-using-pyqgis

レイヤパネルをPythonコンソールで切り替えられたら
プラグインへの実装は簡単にできるよねー

というわけでPythonコンソールを起動して以下のコマンドを実行

# QGIS2系だとimportが必要
# from PyQt4.QtGui import QDockWidget

# レイヤパネルを取得(戻り値は配列)
layersPanel = [x for x in iface.mainWindow().findChildren(QDockWidget) if x.objectName() == 'Layers']

# 表示するぜ
layersPanel[0].setVisible(True)

# 消すぜ
layersPanel[0].setVisible(False)

できた。
objectNameに指定されている名前は上記のループでざーっと表示させてなんとなく探し当てるか
QGISのリポジトリで「qgisapp.cpp」から mLayerTreeDock->setObjectName( "Layers" );みたいに追加しているところを探し当てるかになると思います。

以上

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?