Creating a dock widget
All the panels in QGIS are dock widgets. These widgets can attach to a side of the main window or float freely in a separate window. These panels can contain any other type of widget, which is why they are usually the interface for QGIS plugins. In this recipe, we'll create a dock widget with a text editor widget inside.
Getting ready
Open the QGIS Python console by selecting the Plugins menu and then clicking on Python Console.
How to do it...
We'll create a QTextEdit widget. Then we'll create a QDockWidget and place the QTextEdit
widget inside it. Finally we'll display the dock widget in the main window:
- First, we import the Qt libraries, which contain all the widgets:
from PyQt4.QtCore import * from PyQt4.QtGui import *
- Next, we create the text edit widget with a default message:
te = QTextEdit("<b>Project notes:</b>")
- Now, we create the dock widget with a title:
dw = QDockWidget("QGIS...