With the help of python, I managed to build a small script that replaces all URLs in a text column with images using a delegate. The images where loaded from Microsoft SharePoint using an adapted version of request_ntlm.
import PyQt4
from PyQt4 import QtGui,QtCore
import requests
from requests_ntlm import HttpNtlmAuth, HttpNtlmSspiAuth
from PyQt4.QtGui import QApplication, QTableView
class ImageDelegate(QtGui.QStyledItemDelegate):
def __init__(self, parent):
QtGui.QStyledItemDelegate.__init__(self, parent)
def paint(self, painter, option, index):
# Get Item Data
url = index.model().data(index, QtCore.Qt.EditRole)
if url != '':
style = QtGui.QApplication.style()
opt = QtGui.QStyleOptionGraphicsItem()
opt.rect = option.rect
r = requests.get(url, auth=HttpNtlmSspiAuth())
data = r.content
pixmap = QtGui.QPixmap()
pixmap.loadFromData(data)
if option.rect.x() > 250:
pixmap=pixmap.scaledToWidth(250)
painter.drawPixmap(option.rect.x(), option.rect.y(), pixmap)
dialog = iface.showAttributeTable(iface.activeLayer())
targetColumnIndex = 8 # how to find Index of column?
delegateImage = ImageDelegate(iface)
dialog.findChildren(QTableView)[0].setItemDelegateForColumn(targetColumnIndex, delegateImage)
dialog.findChildren(QTableView)[0].setColumnWidth(targetColumnIndex, 250 )
dialog.findChildren(QTableView)[0].verticalHeader().setDefaultSectionSize(200)
What I couldn't manage by now: how to retrieve the index of a given column (see hardcoded targetColumnIndex in the code above) in the attribute table (QTableView) even when "colxy" is moved or some columns are hidden?