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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:51:34+00:00 2026-05-16T07:51:34+00:00

I’ve got a Widget (QTabeleWidget, QLabels and some QButtons). It was built in Qt-Designer,

  • 0

I’ve got a Widget (QTabeleWidget, QLabels and some QButtons). It was built in Qt-Designer, and now I have to implement some things. For that I need the mousePressEvent.
Usually I would write a subclass and write something like this:

def mousePressEvent(self, event):
    if event.button() == Qt.LeftButton:
        print "left"
    else:
        print 'right'

But I don’t know how to do that for a Widget created in the Designer.
I need it for the QTabeleWidget. Hope someone can help me. I tried to solve the problem with the help of google, but without success.
This site helped me many times, so I thought I’ll give it a shot and ask.

  • 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-16T07:51:35+00:00Added an answer on May 16, 2026 at 7:51 am

    With PyQt there are three different ways to work with forms created in designer:

    1. Use single inheritance and make the form a member variable
    2. Use multiple inheritance
    3. Dynamically generate the members directly from the UI file

    Single Inheritance:

    class MyTableWidget(QTableWidget):
        def __init__(self, parent, *args):
            super(MyTableWidget, self).__init__(parent, args)
            self.ui = YourFormName()
            self.ui.setupUi(self)
            # all gui elements are now accessed through self.ui
        def mousePressEvent(self, event):
            pass # do something useful
    

    Multiple Inheritance:

    class MyTableWidget(QTableWidget, YourFormName):
        def __init__(self, parent, *args):
            super(MyTableWidget, self).__init__(parent, args)
            self.setupUi(self)
            # self now has all members you defined in the form
        def mousePressEvent(self, event):
            pass # do something useful
    

    Dynamically Generated:

    from PyQt4 import uic
    yourFormTypeInstance = uic.loadUi('/path/to/your/file.ui')
    

    For (3) above, you’ll end up with an instance of whatever base type you specified for your form. You can then override your mousePressEvent as desired.

    I’d recommend you take a look at section 13.1 in the PyQt4 reference manual. Section 13.2 talks about the uic module.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6

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.