More

QGIS actions - get currently selected attribute column (with python?)

QGIS actions - get currently selected attribute column (with python?)


I'm trying to open files dynamically through actions. A simple example would be:

Action name: OpenLink

from PyQt4.QtCore import QUrl; from PyQt4.QtWebKit import QWebView; myWV = QWebView (None); myWV.load(QUrl('[% "myColumn" %]')); myWV.show()

However this example is working with a fixed column name (myColumn). What I want to do is execute the action using whatever column in the object attributes I have selected.

Let's say I have three columns:

  • mycolumn
  • myColumn2
  • myLink

when I right-click myLink, I would like to use the value from it in the above action. Is that possible?

Image:


You can use @current_field:

from PyQt4.QtCore import QUrl; from PyQt4.QtWebKit import QWebView; myWV = QWebView (None); myWV.load(QUrl('[% @current_field %]')); myWV.show()