467,920 Members | 1,239 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,920 developers. It's quick & easy.

Re: pyqt4: trouble making custom widget appear in mainwindow

On Sunday 04 May 2008, Lance Gamet wrote:
about 3 years ago I did a bit of Qt3 and 4 on C++, now I am trying to do
something in python.

A QMainWindow subclass as my mainwindow. Its basically a frame with no
widgets of its own.

Several QWidget subclasses each representing a mode of the program, these
widgets should appear in the mainwindow depending on what part of the
program is being used.

I have made the main window and a couple of widgets with designer-qt4 and
generate a Ui_Whatever.py with pyuic4 and subclass that.

My problem is I cant get my widgets to appear in the main window.

My MainWindow.py looks like (imports etc skipped):

class MainWindow(QMainWindow, Ui_MainWindow):
def __init___(self):

def newTeamWizardMode(self):
Widget = QWidget()
self.newTeamWizard = CreateNewTeamWizard(Widget)
self.newTeamWizard.setGeometry(QRect(0,0,90, 160))

My CreateNewTeamWizard is defined like so:

class CreateNewTeamWizard(QWidget, Ui_CreateNewTeamWizard):
def __init___(self, parent = None):
QWidget.__init__(self, parent)

In my main program i make the main window and try and add the widget like

app = Qt.QApplication(sys.argv)
mainWindow = MainWindow()
app.connect(app, Qt.SIGNAL("lastWindowClosed()"), app, Qt.SLOT("quit

One thing i tried was changing the CreateNewTeamWizard in
MainWindow.newTeamWizardMode to CreateNewTeamWizard(Widget, self) to
provide the main window as the parent but I get the following error:

self.newTeamWizard = CreateNewTeamWizard(Widget, self)
TypeError: argument 2 of QWidget() has an invalid type

I have looked for examples, but everything I have found is a bit too
simple. Creating a single window or widget, displaying it as the programs
main window and exiting when the window is closed.

I havent found anything to tell me how to make a widget appear in a
mainwindow how I want.

Any tips?
I think QMainWindow.setCentralWidget() is what you are looking for.
If someone can point me to a nice open source program that uses pyqt4
that might help.
The eric4 IDE probably covers most things you'll ever need.

Jun 27 '08 #1
  • viewed: 804

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by blue_i | last post: by
2 posts views Thread by Harshad | last post: by
3 posts views Thread by Skink | last post: by
25 posts views Thread by Daniel Jonsson | last post: by
5 posts views Thread by Mel | last post: by
2 posts views Thread by jiang.haiyun | last post: by
4 posts views Thread by Daniel Gee | last post: by
3 posts views Thread by ff | last post: by
4 posts views Thread by ff | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.