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 808229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:31:45+00:00 2026-05-15T00:31:45+00:00

I`m starting with PyQt4 and right now I have a problem with events. I

  • 0

I`m starting with PyQt4 and right now I have a problem with events.

I have one main class let say MainWindow. MainWindow has a list of buttons of type ButtonX (inherence form QPushButton). I would like to achieve one of 2 solutions (depends which is easier).

1) After click one of the button from the list I would like to run a one method of MainWindow. I would like to be able to read a source of event there (recognize clicked button)

2) Second solution is to run a method defined in ButtonX class.

What I tried is:

QtCore.QObject.connect(self.getButton(0, 0), QtCore.SIGNAL("clicked()"), self.getButton(0, 0).buttonMethod())

QtCore.QObject.connect(self.getButton(0, 0), QtCore.SIGNAL("clicked()"), self.getButton(0, 0), QtCore.SLOT("incrementValue()"))

and even this line occure suspend Python interpreter

QtCore.QObject.connect(self.getButton(0, 0), QtCore.SIGNAL("clicked()"), self.getButton(0, 0), QtCore.SLOT("incrementValue"))
  • 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-05-15T00:31:46+00:00Added an answer on May 15, 2026 at 12:31 am

    1) After click one of the button from the list I would like to run a one method of MainWindow. I would like to be able to read a source of event there (recognize clicked button)

    You can access the source of an event using QObject.sender(). But, as the instructions indicate, it’s often better to use QSignalMapper or do things in a more object oriented fashion.

    2) Second solution is to run a method defined in ButtonX class.

    Look carefully at what you typed for the last argument of the first connect call:

    self.getButton(0, 0).buttonMethod()
    

    The above will evaluate getButton with parameters 0, 0 and then, on that object, call the buttonMethod method. So, unless buttonMethod returns a method, you are using the return value of buttonMethod as the last parameter to the connect call. If this method returns a function, then this is just fine.

    Rather, I would expect to see something like the following:

    self.getButton(0, 0).buttonMethod # note no parenthesis at end
    

    Take a look at the PyQt examples directory provided with PyQt as they’ll demonstrate the exact syntax and serve as good examples.

    Here’s one small example:

    class MW(QMainWindow):
        def __init__(self, *args)
            QMainWindow.__init__(self, *args)
            layout = QHBoxLayout(self)
            self.b1 = QPushButton("Button1")
            self.b2 = QPushButton("Button2")
            layout.addWidget(self.b1)
            layout.addWidget(self.b2)
            self.connect(self.b1, SIGNAL("clicked()"), self.buttonWasPressed)
            self.connect(self.b2, SIGNAL("clicked()"), self.buttonWasPressed)
    
        def buttonWasPressed(self):
            print "button %s was pressed" % self.sender()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Starting to learn Canvas and have two classes so far (main one to call
starting with priority_queue s, I have a problem like this: I need elements to
I have a GUI developed using pyqt4 which has a run button. on run
Starting at http://developer.android.com/training/index.html I selected the [ FIRST CLASS > ] button which takes
Starting with a list of objects containing two parameters notional and currency, how can
Starting a new rails project and we have a well-thought-out color palette, and want
Starting from this example: http://support.microsoft.com/kb/828736 I have tried to add a test function in
Starting from branch master, to merge a topic branch one just says git merge
Starting with 2.2, scrollbars would disappear once the scrolling has stopped. Is there a
Starting this morning my Eclipse indigo have projects and files with gray light color.

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.