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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:43:08+00:00 2026-05-22T12:43:08+00:00

A PyQT beginner question. I’m wondering how to do something like the following –

  • 0

A PyQT beginner question. I’m wondering how to do something like the following – modify widgets in the main window from outside the main window class. Like so:

class MainWindow(QtGui.QMainWindow):    

    def __init__(self, parent=None):

        super(MainWindow,self).__init__(parent)

        self.ui = Ui_MainWindow()        
        self.ui.setupUi(self)

        self.ui.progressBar.setMaximum(100)
        self.ui.progressBar.setMinimum(0)
        self.ui.progressBar.setValue(0)

        self.connect(self.ui.pushButton, QtCore.SIGNAL('clicked()'), self.slotDoStuff)

    def slotDoStuff(self):
        AnotherFunction()


def AnotherFunction():    
    modify progress bar here...

Is there a way to do something like this? I’d like to subclass the event handlers for various main window actions and not have them all in the MainWindow class. Thanks!

  • 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-22T12:43:08+00:00Added an answer on May 22, 2026 at 12:43 pm

    First, there’s a much better way to connect signals to slots on PyQt:

    self.button.clicked.connect(self.method)
    

    You can use lambda functions to pass extra arguments to methods.

    def do_stuff(arg)
         #do stuff with arg
    

    Then you call

    self.button1.clicked.connect(lambda : do_stuff('btn one'))
    self.button2.clicked.connect(lambda : do_stuff('btn two'))
    

    You can pass whatever you want, including your MainWindow instance to be modified

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

Sidebar

Related Questions

I have a main PyQt window, from which I need to get a string
I'd like PyQt to load an image and display it from the web. Dozens
I am learning PyQt and wonder if one can create custom/owner draw control like
I'm working with PyQt and trying to get video from a webcam to play
I'm developing a PyQt program that will soon switch from an xml type backend
I'm trying to use pyqt to show a custom QDialog window when a button
I am having some issue with layout in pyqt. After closing the items from
i converted recently from wxpython to pyqt and im still facing alot of problems
In PyQt 4.5, I have a layout inside another layout. I'd like to remove
I have a PyQt program used to visualize some python objects. I would like

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.