2010-02-25 79 views
0

我需要的是非常相似的QtMessageBox.information方法,但我需要它构成我的自定义窗口。PyQt4:将QtMessageBox.information功能添加到自定义窗口中

我需要一个标签很少的窗口,一个QtTreeViewWidget,一个QButtonGroup ...这个窗口将从主窗口调用。如果我们调用类,它实现所谓的窗口SelectionWindow,比我需要的是:从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 
    ... 

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

我会感谢任何帮助!

感谢, Tiho

回答

0

我会做这样的事情:

  • 对话窗口buttonbox - ) 连接到接受(> 事件,并拒绝()对话框本身
  • 的插槽
  • 将对话模态设置为应用模式
  • 将对话框的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 
    ... 
+0

redShadow,非常感谢你的回答。最后,我做了一些与您的提案非常相似的内容。 – Tiho 2010-03-09 09:33:56

相关问题