tags:

views:

465

answers:

1

I'm working on a multi form Ruby-Qt program using, and I'm having a problem with controlling secondary windows from the primary one. How can i disable the primary window when any secondary one is open, also how to take a secondary window output to use it on the primary one, and finally, sorry this is a silly one, what is the appropriate method for closing any window (like this.close in .net) ????

+2  A: 

You can make a dialog modal, this disables user interaction with other windows of your application until the user closes the modal window. Use Qt::Dialog.exec instead of Qt::Dialog.show to pop up the window as a modal dialog. This method returns Qt::Dialog::Accepted or Qt::Dialog::Rejected depending on how the user closed the dialog.

To use data from a dialog in the main application window, just save the data somewhere in the dialog class where the main program can access it. For example:

class MyDialog < Qt::Dialog
    attr_reader :data
[...]
    def updateData(new)
        @data = new
    end
end

dlg = MyDialog.new(self)
if (dlg.exec == Qt::Dialog::Accepted)
    @aButton.text = dlg.data
end

If you are using a dialog, you need to exit it with accept() or reject(), in most cases these are connected to the OK and Cancel button:

connect(okButton, SIGNAL('clicked()'), self, SLOT('accept()'))
connect(cancelButton, SIGNAL('clicked()'), self, SLOT('reject()'))

Other windows can be closed with the close() method.

TobiX