PyQt - multiple window instances?

G

gregarican

I have an PyQt app were I need one of the windows to be able to be
opened more than one at a time. When I try to open it I only get one
instance at the same time. The main class is the QWidget() class with a
QGridLayout() displaying the various window components.

Is there a certain flag I need to set or different constructor I need
to use to allow the window to be opened more than one at a time?

Here's a brief snippet of the code that displays the window:

def new_showing(self):
""" This method creates a new contact showing record. """

if self.flag == 'KNOWN':
try:
test_contact = self.entry_id
except:
QMessageBox.warning(self, "Qt CRAM", "There is no
contact record loaded.\nPlease select a contact record first.")
return

self.new_show_widget=QWidget()
self.new_show_widget.resize(240, 280)
self.new_show_widget.setCaption('Qt CRAM - Contact Showings')

# Define the Qt layout to be used for the window.
self.new_show_grid=QGridLayout(self.new_show_widget, 8, 2)

# bunch of widgets displaying stuff

self.new_show_widget.show()
 
D

Diez B. Roggisch

gregarican said:
I have an PyQt app were I need one of the windows to be able to be
opened more than one at a time. When I try to open it I only get one
instance at the same time. The main class is the QWidget() class with a
QGridLayout() displaying the various window components.

Is there a certain flag I need to set or different constructor I need
to use to allow the window to be opened more than one at a time?

No. Must be something you're doing - I guess it might be that you should keep a reference to the old windows, otherwise
they might go away when garbage-collected.

Diez
 
G

gregarican

The window isn't being created as a new class instance or anything. The
main class is the application main window as a whole and this
particular window is just part of that class. I have typed data into
the window, then tried to open up a new window. But when I do the
window where I have typed data disappears and is replaced by a new
window that's blank. What's the easiest way to keep a reference to the
old window?
 
D

Diez B. Roggisch

gregarican said:
The window isn't being created as a new class instance or anything.

Yes it is. QWidget() creates a new instance of QWidget.
> The
main class is the application main window as a whole and this
particular window is just part of that class. I have typed data into
the window, then tried to open up a new window. But when I do the
window where I have typed data disappears and is replaced by a new
window that's blank. What's the easiest way to keep a reference to the
old window?

By putting it into a list for example?


Diez
 
G

gregarican

Diez said:
Yes it is. QWidget() creates a new instance of QWidget.



By putting it into a list for example?

Diez

Perfect! Thanks for the tip. That worked perfectly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top