简体   繁体   English

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

[英]How to open a QDialog window with a function passing args?

I'm in big trouble, I can't figure it out how to open my window "PlotWindow" with my "OpendPlotWindow" function. 我很麻烦,我无法弄清楚如何使用“ OpendPlotWindow”函数打开窗口“ PlotWindow”。 I'm new in PyQt so it is a dumb question, but I really don't understand what's wrong in my code 我是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()

The problem: when I run my code, it comes to OpenPlotWindow which get all data needed, but it never enter into PlotWindow... 问题是:当我运行代码时,它涉及的是OpenPlotWindow,它获取所需的所有数据,但从未输入PlotWindow ...

Please can you help me? 请你能帮我吗?

As per the docs for QPushButton 's super class QAbstractButton , clicked takes one argument, bool checked = false . 根据QPushButton的超类QAbstractButton 的文档clicked QAbstractButton一个参数, bool checked = false It's actually pretty useless on QPushButton as far as I've seen, but nevertheless, your function needs to account for this. 据我所知,它实际上在QPushButton上几乎没有用,但尽管如此,您的函数仍需要考虑这一点。 Try this line instead 试试这行

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM