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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:11:23+00:00 2026-05-27T15:11:23+00:00

During regular intervals of my program, a block (of 3 stacked) widgets need to

  • 0

During regular intervals of my program, a block (of 3 stacked) widgets need to be added to a horizontal layout. Since the widgets within each block are important to eachother, I wish to encapsulate each stack as it’s own widget (making the layout adding business much easier).

I’m having trouble getting PyQt4 to recognise my ‘stack’ as a widget.

I made the widget stack in Qt Designer (as form: widget) and converted it to a .py via
‘pyuic4 DesignerFile.ui > ClassFile.py’.

Now I can’t seem to add this ‘stack’ (parent widget of 3 child widgets) to the layout via .addWidget( Class ).

I tried constructing a super class of the stack class (because I need to add more functionality to the stack) but the instance of the class is either…

  • Not recognised as a widget
  • Invisible
  • defective because I’ve no idea on how to structure the super class.

Here’s what I’m failing with at the moment (though it’s about the 8th class structure I’ve tried):

from ClassFile import ClassCode

class Stack(ClassCode):
    def __init__(self,parent= None):
        QtGui.QWidget.__init__(self,parent)

Could somebody help me structure this or lead me to some good examples?
(I’ve mimicked the code in both the following sources but with no avail!!
http://lateral.netmanagers.com.ar/stories/27.html#what-you-need-to-follow-the-tutorial
http://zetcode.com/tutorials/pyqt4/customwidgets/ )

Thanks!

Specs:
python 2.7.2
PyQt4
Windows 7

  • 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-27T15:11:23+00:00Added an answer on May 27, 2026 at 3:11 pm

    When you compile a python module from a ui file with the default options, it will (amongst other things) generate a simple “setup” class. In outline, the setup class will look like this:

    class Ui_ClassCode(object):
        def setupUi(self, ClassCode):
            ClassCode.setObjectName("ClassCode")
            # bunch of boiler-plate ui code goes here
            self.retranslateUi(ClassCode)
            QtCore.QMetaObject.connectSlotsByName(ClassCode)
    
        def retranslateUi(self, ClassCode):
            pass
    

    There are a couple of issues to notice here that are relevant to the question.

    Firstly, the setup class is designed to be used as a mixin rather than as a direct subclass. It’s task is to “inject” ui into a host widget that is passed to the setupUI method.

    Secondly, the setup class is given an ugly, unpythonic identifier that is created by prepending “Ui_” to the objectName property that was set in Designer.

    Fortunately, pyuic4 provides a way to bypass these two issues. All that’s required is to use the -w option when compiling the python module from the ui file:

    pyuic4 -w designerfile.ui > classfile.py
    

    This will add a wrapper class that (1) can be easily subclassed, and (2) has the class-name that you damn well gave it in Qt Designer.

    The wrapper class will look something like this:

    class ClassCode(QtGui.QWidget, Ui_ClassCode):
        def __init__(self, parent=None, f=QtCore.Qt.WindowFlags()):
            QtGui.QWidget.__init__(self, parent, f)
    
            self.setupUi(self)
    

    As you can see, it doesn’t do anything special: you could easily replicate what it does in your own code. But, IMO, it does make the compiled modules much more intuitive to use.

    For example:

    from PyQt4 import QtGui, QtCore
    from classfile import ClassCode
    
    class Stack(ClassCode):
        def __init__(self, parent=None):
            ClassCode.__init__(self, parent)
    
    class Window(QtGui.QMainWindow):
        def __init__(self):
            QtGui.QMainWindow.__init__(self)
            self.stack = Stack(self)
            self.setCentralWidget(self.stack)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

During the course of my program execution, a number of threads are started. The
My Questions is Is there any regular expression engine that does Just-In-Time compiling during
I have a situation. Sharepoint translates server side Linkfields to regular HTML tag during
I need to be able to ssh from a Java program into a remote
I would like to specify the regular expression during run-time, not compile-time. So that
i have a multi environment program that runs on windows ce machines, regular pc
During the work on my iPhone application the icon changed from time to time.
During Session Start, one has access to the Request object. How about Session End,
During our build process, we run sqlldr to populate our database with some sample
During the process of building software applications, you would start testing what you 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.