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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:41:10+00:00 2026-05-20T17:41:10+00:00

lets suppose you have 3 QRadioButtons instances inside a class self.Option1 = QRadioButton() self.Option2

  • 0

lets suppose you have 3 QRadioButtons instances inside a class

self.Option1 = QRadioButton()
self.Option2 = QRadioButton()
self.Option2 = QRadioButton()

(for brevity i didn’t wrote the entire script)
and you want to use them to execute a particular function when the user clicks it, so you do

self.connect(self.Option1,SIGNAL("clicked()"), self.myFunction)
self.connect(self.Option2,SIGNAL("clicked()"), self.myFunction)
self.connect(self.Option2,SIGNAL("clicked()"), self.myFunction)

How do i pass arguments to to myFunction so it knows wich of the QRadioButtons was clicked by the user? so i can do stuff like

def myFunction(choice):
   if choice == Option1:
       do something
   if choice == Option2:
       do something

Right now i have 3 functions, each for every connect like this

self.connect(self.Option1,SIGNAL("clicked()"), self.myFunction1)
self.connect(self.Option2,SIGNAL("clicked()"), self.myFunction2)
self.connect(self.Option2,SIGNAL("clicked()"), self.myFunction2)

And this approach works just fine, but you can see how quickly the code can grow because with every widget i add i’ll have to write at least one new function or modify the existing ones, its going to be a maintainance nightmare(not to mention that it looks ugly and it prevents code reuse).

A quick visit to google got me this:

    self.label = QLabel(" ")

    self.connect(self, SIGNAL("didSomething"),
                 self.update_label)
    self.do_something()

def do_something(self):
    self.emit(SIGNAL("didSomething"), "important", "information")

def update_label(self, value1, value2):
    self.label.setText(value1 + " " + value2)

(again i didnt include the entire script but you can check it out here)
What he did was creating a method to define a custom emitter that sends arguments when emitted and then activated it manually using

self.do_something()

So naturally, the connect function picks this emition and pass the arguments to the function update_label, partially achieving what i want to do. But he is doing it manually, is there a way to automatically “intercept” standard signals(for example the clicked() signal QRadioButtons emit) and add arguments to it, so they get passed to a function to work with them?

Thanks in advance

  • 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-20T17:41:11+00:00Added an answer on May 20, 2026 at 5:41 pm

    The Qt solution of this problem is QSignalMapper I think. But I had the same problem before, and I figured out using “partial” function is simplier. Use it like that:

    from functools import partial
    
    self.connect(self.Option1,SIGNAL("clicked()"), partial(self.myFunction, 1))
    self.connect(self.Option2,SIGNAL("clicked()"), partial(self.myFunction, 2))
    self.connect(self.Option3,SIGNAL("clicked()"), partial(self.myFunction, 3))
    

    For more info: http://docs.python.org/library/functools.html#functools.partial

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

Sidebar

Related Questions

Lets suppose I have a PHP file file1.php . Something like this: <?php class
Lets suppose i have a super class WorkStation , and two subclass StationNormal ,
Lets Suppose that I have made a custom authentication module that inherits IHttpModule class.
Lets suppose I have a RESTful service which has a list of tasks. GET
I was recently asked this question in an interview. Lets suppose I have 2000
I'm saving a struct into a .dat file. Lets suppose I have to edit
Lets suppose that I have the following simple query var q = from p
Lets suppose that I have some pages some.web/articles/details/5 some.web/users/info/bob some.web/foo/bar/7 that can call a
Lets suppose that I have a Category table with a column that holds the
Let's suppose I have a css class named foo. I would like to have

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.