PyQt - multiple window instances?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gregarican

    #1

    PyQt - multiple window instances?

    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(sel f):
    """ This method creates a new contact showing record. """

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

    self.new_show_w idget=QWidget()
    self.new_show_w idget.resize(24 0, 280)
    self.new_show_w idget.setCaptio n('Qt CRAM - Contact Showings')

    # Define the Qt layout to be used for the window.
    self.new_show_g rid=QGridLayout (self.new_show_ widget, 8, 2)

    # bunch of widgets displaying stuff

    self.new_show_w idget.show()

  • Diez B. Roggisch

    #2
    Re: PyQt - multiple window instances?

    gregarican schrieb:[color=blue]
    > 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?[/color]

    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

    Comment

    • gregarican

      #3
      Re: PyQt - multiple window instances?

      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?

      Comment

      • Diez B. Roggisch

        #4
        Re: PyQt - multiple window instances?

        gregarican schrieb:[color=blue]
        > The window isn't being created as a new class instance or anything.[/color]

        Yes it is. QWidget() creates a new instance of QWidget.
        [color=blue]
        > 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?[/color]

        By putting it into a list for example?


        Diez

        Comment

        • gregarican

          #5
          Re: PyQt - multiple window instances?

          Diez B. Roggisch wrote:
          [color=blue][color=green]
          > > The window isn't being created as a new class instance or anything.[/color]
          >
          >
          > Yes it is. QWidget() creates a new instance of QWidget.
          >[color=green]
          > > The[/color]
          >
          >
          >[color=green]
          > > 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?[/color]
          >
          >
          > By putting it into a list for example?
          >
          > Diez[/color]

          Perfect! Thanks for the tip. That worked perfectly.

          Comment

          Working...