2

using PyQGIS, I need to create a map tip using this HTML code: ID = [% ID %] and style it like the picture below (white text and black background). I don't know how to use CSS in this case.

If is not possible create a map tip using PyQGIS, can I maybe save it in a .qml file e set it using PyQGIS in someway?

enter image description here

4

You can set some CSS in your maptip and using PyQGIS too:

layer = iface.activeLayer()

expression = """
<style>
html *{
background-color: black ;
color: white;
}
</style>

Name : [% "nom" %]
"""
layer.setMapTipTemplate(expression)

PS : I'm trying to remove the white border line.

| improve this answer | |
  • Thank you very much, this is what I was looking for. P.s. I know that this is another question, but do you know if you can reduce map tips delay using PyQGIS? Thanks again – Lorenzo Mar 11 at 18:57
  • 1
    QgsSettings().setValue('qgis/mapTipsDelay', 500). Be careful, this is a QGIS user setting. – etrimaille Mar 11 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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