0

How can I add a custom panel to QGIS using Python?

For example, I want to add a panel that has a button that opens a dialogue box to choose a folder and a list in which all the tif files in the folder will be listed.

1 Answer 1

7

Your question is quite broad but here is a short example to get you started. It will make a QgsFileWidget (a native widget for selecting directories/files) and place it in a dock widget on the right on the screen.

def make_filewidget():
    """ generate a file widget in a container """
    
    # create the file widget
    file_widget = QgsFileWidget()
    file_widget.setObjectName('filewidget_example')
    
    # the container for the file widget that will be added to the interface
    container = QDockWidget('A file widget in a dockable container')
    container.setWidget(file_widget)
    container.setVisible(True)
    
    return container, file_widget
    
# generate the table
fw = make_filewidget()

# add the table container to the interface
iface.addDockWidget(Qt.RightDockWidgetArea, fw[0])

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.