Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access QGIS measurement (and all QWidgetAction) widget with a deterministic approach #22024

Open
qgib opened this issue Dec 18, 2015 · 2 comments
Labels
Feature Request Map Tools Related to non-digitizing map tools

Comments

@qgib
Copy link
Contributor

qgib commented Dec 18, 2015

Author Name: Thomas Gratier (@ThomasG77)
Original Redmine Issue: 14011

Redmine category:map_tools


To access the measurement widget in the toolbar that contains "Measure Line", "Measure Area" and "Measure Angle", I have to do the following:

    iface.attributesToolBar().actions()[8]


The problem: it's not deterministic if I choose to add or remove buttons in the "Attributes Toolbar"

If I do below code, It's again not deterministic because I depend from the translated string


    from PyQt4.QtGui import QWidgetAction
    
    for action in iface.attributesToolBar().actions():
        if isinstance(action, QWidgetAction):
            if action.defaultWidget().actions()[0].text() in ["Measure Line", "Measure Area", "Measure Angle"]:
                print action.defaultWidget().actions()[0].text()

So, I would expect something like

    from PyQt4.QtGui import QWidgetAction
    
    for action in iface.attributesToolBar().actions():
        if isinstance(action, QWidgetAction):
            if action.data() == "qwidget_measure":
                print "It the measurement QWidget"

I don't know if I missed an alternate better way.

If there are not better way, the proposed changed would make action.data() contains an id instead of None at the moment.

I also don't know if it's the best solution too (not enough year of experience with Qt/PyQt)

@qgib
Copy link
Contributor Author

qgib commented Apr 30, 2017

Author Name: Giovanni Manghi (@gioman)


  • easy_fix was configured as 0

@qgib
Copy link
Contributor Author

qgib commented May 10, 2017

Author Name: Regis Haubourg (@haubourg)


  • category_id was changed from Actions to Map Tools
  • description was changed from To access the measurement widget in the toolbar that contains "Measure Line", "Measure Area" and "Measure Angle", I have to do the following:
    iface.attributesToolBar().actions()[8]

The problem: it's not deterministic if I choose to add or remove buttons in the "Attributes Toolbar"

If I do below code, It's again not deterministic because I depend from the translated string

    from PyQt4.QtGui import QWidgetAction
    
    for action in iface.attributesToolBar().actions():
        if isinstance(action, QWidgetAction):
            if action.defaultWidget().actions()[0].text() in ["Measure Line", "Measure Area", "Measure Angle"]:
                print action.defaultWidget().actions()[0].text()

So, I would expect something like

    from PyQt4.QtGui import QWidgetAction
    
    for action in iface.attributesToolBar().actions():
        if isinstance(action, QWidgetAction):
            if action.data() == "qwidget_measure":
                print "It the measurement QWidget"

I don't know if I missed an alternate better way.

If there are not better way, the proposed changed would make action.data() contains an id instead of None at the moment.

I also don't know if it's the best solution too (not enough year of experience with Qt/PyQt)

to To access the measurement widget in the toolbar that contains "Measure Line", "Measure Area" and "Measure Angle", I have to do the following:

    iface.attributesToolBar().actions()[8]

The problem: it's not deterministic if I choose to add or remove buttons in the "Attributes Toolbar"

If I do below code, It's again not deterministic because I depend from the translated string

    from PyQt4.QtGui import QWidgetAction
    
    for action in iface.attributesToolBar().actions():
        if isinstance(action, QWidgetAction):
            if action.defaultWidget().actions()[0].text() in ["Measure Line", "Measure Area", "Measure Angle"]:
                print action.defaultWidget().actions()[0].text()

So, I would expect something like

    from PyQt4.QtGui import QWidgetAction
    
    for action in iface.attributesToolBar().actions():
        if isinstance(action, QWidgetAction):
            if action.data() == "qwidget_measure":
                print "It the measurement QWidget"

I don't know if I missed an alternate better way.

If there are not better way, the proposed changed would make action.data() contains an id instead of None at the moment.

I also don't know if it's the best solution too (not enough year of experience with Qt/PyQt)

@qgib qgib added Feature Request Map Tools Related to non-digitizing map tools labels May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Map Tools Related to non-digitizing map tools
Projects
None yet
Development

No branches or pull requests

1 participant