tags:

views:

60

answers:

1

Hi everyone,

what I need is something very alike QtMessageBox.information method, but I need it form my custom window.

I need a one window with few labels, one QtTreeViewWidget, one QButtonGroup … This window will be called from main window. If we call class that implements called window as SelectionWindow, than what I need is:

class MainWindow(QtGui.QMainWindow):
    ...
    def method2(self):
        selWin = SelectionWindow()
        tempSelectionValue = selWin.getSelection()
        # Blocked until return from getSelection
        self.method1(tempSelectionValue)
        ...

class SelectionWindow(QtGui.QMainWindow):
    ...
    def getSelection(self):
        ...
        return selectedRow
    ...

Method getSelection from SelectionWindow should pop up selection window and at the end return row selected in QTreeViewWidget. I want that main window remains blocked until user selects one row in selection window and confirms it by button. I hope that you will understand what I need.

I will appreciate any help!

Thanks, Tiho

A: 

I would do something like this:

  • dialog window with buttonbox -> events connected to accept() and reject() slots of the dialog itself
  • set the dialog modality to something like application modal
  • call the exec_() method of the dialog to keep it blocking until the user chooses ok/cancel
  • after the execution of the exec_() method terminates, you can read what you need from the dialog widgets.

Something like this should fit your needs:

class SelectionWindow(QtGui.QMainWindow):
    ...
    def getSelection(self):
        result = self.exec_()
        if result:
            # User clicked Ok - read currentRow
            selectedRow = self.ui.myQtTreeViewWidget.currentIndex()
        else:
            # User clicked Cancel
            selectedRow = None
        return selectedRow
    ...
redShadow
redShadow, thank you very much for your answer. At the end I did something very similar to your proposal.
Tiho