代码之家  ›  专栏  ›  技术社区  ›  Tiho

PyQt4:将QtMessageBox.information功能添加到自定义窗口

  •  0
  • Tiho  · 技术社区  · 16 年前

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

    方法GetSelectionWindow中的getSelection应弹出选择窗口,并在QTreeViewWidget中选择的返回行末尾。我希望主窗口保持阻塞状态,直到用户在选择窗口中选择一行并通过按钮确认。我希望你能理解我需要什么。

    我将感谢任何帮助!

    蒂霍

    1 回复  |  直到 16 年前
        1
  •  0
  •   redShadow    16 年前

    我会这样做:

    • 连接到accept()和
    • 将对话框模态设置为类似于应用程序模态

    这样的东西应该适合你的需要:

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