1

I'm developing a plugin for QGIS 2.18 where a user can obtain some statistics from a layer, something similar to this:

Raster info

The above tool can be accessed from the menubar:

Raster > Miscellaneous > Information

What kind of Qt object is the box above and how can I print information not only in a similar format but also in an efficient manner?


At the moment, I'm sending text to a QTextBrowser using something like:

self.dockwidget.textBrowser.setText(str('Layer name: ' + str(layer.name()) +
                            '\nDate: 20/02/2017' +
                            '\nSize: 5 Mb' + 
                            ...))

Current report

1 Answer 1

1

We can use a QListWidget to create a list of items and set it to use alternating row colours:

listWidget = self.dockwidget.listWidget
listWidget.setAlternatingRowColors(True)

layer = self.iface.activeLayer()
layer_dict = {'  Layer name': layer.name(),
              '   Date': '20/02/2017',
              '    Size': '5 Mb'}

listWidget.clear()
row = 0
for key, value in layer_dict.items():
    listWidget.insertItem(row, key + ': ' + value)
    row = row + 1

Example:

Example

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.