Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8750731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:55:05+00:00 2026-06-13T12:55:05+00:00

I have the following outline of a Python program (using PyQt4): class Polygon( QtGui.QGraphicsItem

  • 0

I have the following outline of a Python program (using PyQt4):

class Polygon( QtGui.QGraphicsItem ):

    def __init__(self):
        super(Polygon, self).__init__()

    def addpoint( self, point ):
        if last_point: 
            # trying to add auto-save here

class MainWidget(QtGui.QWidget):

    openFileName = ""
    list_of_polygons = []

    def __init__(self):
        super(MainWidget, self).__init__()

    def openFile( self ):
        call dialog
        self.openFileName = ...

    def saveFile( self ):
        # needs to access a couple something with self.variables, like self.openFileName


def main():

    app = QtGui.QApplication(sys.argv)
    ex = MainWidget()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

Functionality is an image viewer where I’m creating polygons to tag object. I’d like to call an auto-save once a polygon has been created.

So for saving a polygon I need to call it from the saveFile function MainWidget class. My problem is that the saving functionality is implemented in the MainWidget class, and I don’t know how to access them from inside the Polygon class.

What would be the best idea to do this? Should I make saveFile global? If yes, then how do I access the self. variables of the MainWidget?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:55:06+00:00Added an answer on June 13, 2026 at 12:55 pm

    You probably need to pass the widget object to the Polygon when you create it so that it knows what its “parent” widget object is:

    class Polygon( QtGui.QGraphicsItem ):
    
        def __init__(self, parent):
            self.parent = parent
            # ...
    

    (and then foo = Polygon(your_widget) when you create it).


    Then you can just call self.parent.saveFile(...) or whatnot.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to XStream I have following DTO @XStreamAlias(outline) public class OutlineItem implements
I have following DTO @XStreamAlias(outline) public class OutlineItem implements java.io.Serializable { private static final
I have the following HTML: <div id=showDropZone class=ui-droppable style=position: absolute; z-index: 1; outline-style: none;
I have a scenario outline table that looks like the following: Scenario Outline: Verify
I have following nested objects. I am using @Valid for validation in my controller.
I have the following code to draw a square outline with the following code.
I have the following program which I'd like to get it fixed. Not sure
I have the following problem, i need the ul[editable] li class to be dominant
I have the following code: <a href=main.html class=admin><div class=buttonlabel>Admin</div></a> and CSS a.admin { display:block;
I have the following two tables (basic outline): Tbl_CategoryType ID LevelID Description Tbl_Levels ID

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.