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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:21:22+00:00 2026-06-07T01:21:22+00:00

I want to inherit widget1 to use its methods but I get : TypeError:

  • 0

I want to inherit widget1 to use its methods but I get :

"TypeError: Error when calling the metaclass bases Cannot create a 
consistent method resolution order (MRO) for bases widget1, QWidget"

when I run the program. Can you explain to me why this happen?

thank.

from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4 import QtCore, QtGui
import sys

class widget1(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)

class widget2(QtGui.QWidget, widget1):
    def __init__(self):
        QtGui.QWidget.__init__(self)


if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    test = widget1()
    test.show()
    sys.exit(app.exec_()) 
  • 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-07T01:21:24+00:00Added an answer on June 7, 2026 at 1:21 am

    Multiple Inheritance in PyQt4

    It is not possible to define a new Python class that sub-classes from
    more than one Qt class.

    There are multiple alternative design decisions you can use, which makes multiple QObject inheritance unnecessary.

    Simple inherit from the single parent class

    class widget1(QtGui.QWidget):
        def __init__(self):
            super(widget1, self).__init__()
    
        def foo(self): pass
        def bar(self): pass
    
    class widget2(widget1):
        def __init__(self):
            super(widget2, self).__init__()
    
        def foo(self): print "foo"
        def baz(self): pass
    

    Composition

    class widget2(QtGui.QWidget):
        def __init__(self):
            super(widget2, self).__init__()
            self.widget1 = widget1()
    

    Make one of the classes a mixin class, which is not a QObject:

    class widget1(QtGui.QWidget):
        def __init__(self):
            super(widget1, self).__init__()
    
        def foo(self): print "foo"
        def bar(self): pass
    
    class MixinClass(object):
        def someMethod(self):
            print "FOO"
    
    class widget2(widget1, MixinClass):
        def __init__(self):
            super(widget2, self).__init__()
    
        def bar(self): self.foo()
        def baz(self): self.someMethod()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to inherit to extend the C# string class to add methods like
OO Design question. I want to inherit singleton functionality into different hierarchies of classes.
I have a model called Person. I want User to inherit from Person. class
I want to generate a choicelist for all specs that inherit from imagekit.specs.ImageSpec .
I have 2 classes both inherit from the same interface. i want sometimes to
I want to create a Class, say MyDiv , which inherits from the original
Suppose I have table Person table Employee, which inherits Person. I want to get
When you want to inherit from a class in C++, is it illegal to
I have a base type that I want to inherit from, for all my
I want to inherit the DevExpress ComboBoxEdit control, and am wondering if naming my

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.