I want to create a module in Qgis, my raster calculator, I'm stuck in the moment as it is possible to read raster files, just like in Qgis. If we open the raster calculator Qgis, we see in the raster channel our raster files with which we can perform mathematical operations

enter image description here

In my code it reads the raster channel as plain text

def run(self):
    """Run method that performs all the real work"""
    layer_list = []
    layers = self.iface.legendInterface().layers()
    for layer in layers:

    # show the dialog
    # Run the dialog event loop
    result = self.dlg.exec_()
    # See if OK was pressed
    if result:
        # Do something useful here - delete the line containing pass and
        # substitute with your code.

How now to specify what he would perceive in the listWidget, how exactly the raster (this is necessary so that later I could add the functions Gdal and read the channels of the raster)

  • As you edit your question the answer seems completely out... I think you should let the question as it was (to keep cohenrence in the discussion) and start a new question where you will have the answer you deserve.
    – YoLecomte
    Jun 22, 2017 at 11:33

1 Answer 1


QTextEdit is probably not the good Widget for you. Maybe you can try with something like QListWidget. You can use it as in this example:https://wiki.python.org/moin/PyQt/Adding%20items%20to%20a%20list%20widget

   1 import sys
   2 from PyQt4.QtGui import *
   4 layers = self.iface.legendInterface().layers()
   5 listWidget =  self.dlg.yourQListWidget()
   7 for layer in layers:
   8     item = QListWidgetItem(layer.name())
   9     listWidget.addItem(item)

And you can get documentation :http://pyqt.sourceforge.net/Docs/PyQt4/qlistwidget.html

  • Thanks, this widget fits better, but how can I move all active layers to this widget? I inserted the code, but your widget remains just as empty
    – vaza gena
    Jun 22, 2017 at 8:50
  • The code is just an example. You have to modify it to fit to your needs. I have edited my post to propose something more coherent with your case.
    – YoLecomte
    Jun 22, 2017 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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