0

我需要的是非常相似的 QtMessageBox.information 方法,但我需要它形成我的自定义窗口。

我需要一个带有少量标签的窗口,一个 QtTreeViewWidget,一个 QButtonGroup……这个窗口将从主窗口调用。如果我们将实现称为窗口的类称为 SelectionWindow,那么我需要的是:

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
    ...

来自 SelectionWindow 的方法 getSelection 应该会弹出选择窗口,并在最后返回 QTreeViewWidget 中选择的行。我希望主窗口保持阻塞状态,直到用户在选择窗口中选择一行并通过按钮确认。我希望你能理解我的需要。

我将不胜感激任何帮助!

谢谢,蒂霍

4

1 回答 1

0

我会做这样的事情:

  • 带有按钮框的对话框窗口 -> 事件连接到对话框本身的 accept() 和 reject() 插槽
  • 将对话框模式设置为类似于应用程序模式的内容
  • 调用对话框的 exec_() 方法使其保持阻塞状态,直到用户选择确定/取消
  • 在 exec_() 方法的执行终止后,您可以从对话框小部件中读取您需要的内容。

像这样的东西应该适合您的需求:

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
    ...
于 2010-03-02T11:16:48.180 回答