2

How can I get the specified quadrant of a label using PyQGIS?

The print statements below return 1 and 0 no matter which option I pick in the dialog.

palyr = labeling.settings()
print(palyr.placement)
print(palyr.QuadrantPosition())

quad

2

You can find the quadrant position by using QgsPalLayerSettings::quadOffset():

layer.labeling().settings().quadOffset

This returns an enum integer reflecting the QuadrantPosition (e.g. 0 = QuadrantAboveLeft, 1 = QuadrantAbove etc.). We can create a dictionary to contain these values and then get the quadrant position name using something like:

layer = iface.activeLayer()

quads = {
        0: 'QuadrantAboveLeft',
        1: 'QuadrantAbove',
        2: 'QuadrantAboveRight',
        3: 'QuadrantLeft',
        4: 'QuadrantOver',
        5: 'QuadrantRight',
        6: 'QuadrantBelowLeft',
        7: 'QuadrantBelow',
        8: 'QuadrantBelowRight'
        }

quads[layer.labeling().settings().quadOffset]
>>> 'QuadrantAboveRight'

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.