如何使用传递args的函数打开QDialog窗口?

时间:2018-05-30 15:18:09

标签: python pyqt pyqt5

我遇到了大麻烦,我无法弄清楚如何打开我的窗户" PlotWindow"与我的" OpendPlotWindow"功能。我是PyQt的新手,所以这是一个愚蠢的问题,但我真的不明白我的代码中的错误

PlotWindow:

class PlotWindoW(QDialog):
    def __init__(self,x,y, parent=None): 
        super(Window, self).__init__(parent)
        self.figure = plt.figure()
        self.canvas = FigureCanvas(self.figure)
        self.toolbar = NavigationToolbar(self.canvas, self)
        self.plot(x,y)
        layout = QVBoxLayout()
        layout.addWidget(self.toolbar)
        layout.addWidget(self.canvas)
        self.setLayout(layout)
        self.show()
    def plot(self,x,y):
        self.figure.clear()
        ax = self.figure.add_subplot(111)
        ax.plot(x,y)
        self.canvas.draw()

PlotSetting:

class PlotSetting(QWidget):
    def __init__(self,fileNameFm,fileNameMesh,fileNameSmry,fileNameXY, parent=None):
        super(QWidget, self).__init__(parent)
        print("setting start")

        donnees.fileFm=fileNameFm
        donnees.fileMesh=fileNameMesh
        donnees.fileSmry=fileNameSmry
        donnees.fileXY=fileNameXY

        self.layout = QVBoxLayout(self)

        self.tabs = QTabWidget()
        self.tab1 = QWidget()   
        self.tabs.sizeHint() 

        self.tabs.addTab(self.tab1,"Setting Mesh")

        LabelFm = QLabel(donnees.fileFm)
        LabelMesh = QLabel(donnees.fileMesh)

        btnNe=QPushButton("Choose Ne", self)
        btnNe.clicked.connect(self.getInteger)

        FmPlotBtn=QPushButton("Plot Mesh File", self)
        FmPlotBtn.clicked.connect(self.GetDataFm)

        self.tab1.layout = QVBoxLayout(self)
        self.tab1.layout.addWidget(LabelFm)
        self.tab1.layout.addWidget(LabelMesh)
        self.tab1.layout.addWidget(btnNe)
        self.tab1.layout.addWidget(FmPlotBtn)
        self.tab1.setLayout(self.tab1.layout)

        self.layout.addWidget(self.tabs)
        self.setLayout(self.layout)

    def getInteger(self):
        donnees.Ne, okPressed = QInputDialog.getInt(self, "Get integer","Ne:", 66, 66, 98, 2)
        if okPressed:
            print(donnees.Ne)

    def GetDataFm(self):
        print('plot start') 
        data = {}
        data = Fm( donnees.fileFm , donnees.fileMesh )
        x,y=PloterFm(data,donnees.Ne)
        print(x[0],y[0])
        self.OpenPlotWindow(x,y)

    def OpenPlotWindow(self, x, y):
        print("OpenPlotWIndow is running")
        print(x[0],y[0])
        self.ThirdWindow = PlotWindoW(x,y)
        self.ThirdWindow.show()

问题:当我运行我的代码时,它来到OpenPlotWindow,它可以获得所需的所有数据,但它永远不会进入PlotWindow ......

请你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

根据QPushButton的超级QAbstractButton的{​​{3}},clicked只接受一个参数bool checked = false。就我所见,它在QPushButton上实际上毫无用处,但是,你的功能需要考虑到这一点。请尝试使用此行

def GetDataFm(self, clicked=False):
    ....