I am building a QGIS-Plugin retrieving time-series raster data from several sources, which is then supposed to be visualized (so far separately and manually) via the Temporal Controller widget, added in QGIS 3.14.

So far, I am opening the Temporal Controller on plugin startup via

        for i in iface.mainWindow().findChildren(QtWidgets.QDockWidget):
          if i.objectName() == 'Temporal Controller':

For user convenience, I am trying to add the Temporal Controller widget within my custom widget, which contains the other functions of my plugin. I.e. the Temporal Controller is simply supposed to be displayed as-is within my plugin's own UI.

Unfortunately, I have so far only worked using Qt Designer, and my experience building a UI from code is very limited. I have not found an example that this is possible.

Is it at all possible to import an existing widget into another widget?


Yes, this fairly straightforward to do, although examples aren't necessarily easy to find. Some examples of a layout without the Qt designer can be found in the crayfish plugin: https://github.com/lutraconsulting/qgis-crayfish-plugin/blob/master/crayfish/gui/plot_3d_widget.py

For reference, the documentation of the Temporal Controller widget can be found here: https://qgis.org/pyqgis/3.14/gui/QgsTemporalControllerWidget.html

Here's an example:

from PyQt5.QtWidgets import QWidget, QPushButton, QHBoxLayout
from qgis.gui import QgsTemporalControllerWidget

class MyWidget(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.temporal_controller = QgsTemporalControllerWidget()
        self.push_button = QPushButton("Click me!")

        layout = QHBoxLayout()

    def f(self):
        # Does nothing, just for illustration

Basically, every object you have available in the Qt Designer is available here. You can use the .addWidget methods, .addLayout, and .setLayout to build your menus without the Qt designer. These are PyQt5 Widgets, so that's where you'd have to look for the documentation.

As a general note, I'm expecting this temporal controller to be a separate instance, so I don't think it will stay in sync with the "default" temporal controller. You could probably write some methods to get them to sync though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.