I am currently working in a panel in Nuke 11 that opens a QDialog and I was wondering how to get a value from it into my main class when I close my QDialog ? The QDialog is in a different class. This is a simplified example that shows my problem :
import nuke
from nukescripts import panels
try:
## < Nuke11
import PySide.QtGui as QtGui
import PySide.QtCore as QtCore
except:
## >= Nuke11
import PySide2.QtCore as QtCore
import PySide2.QtGui as QtGui
import PySide2.QtWidgets as QtGui
from PySide2.QtWidgets import QWidget as QWidget
class Example(QtGui.QWidget):
def __init__(self):
super(Example,self).__init__()
layout = QtGui.QVBoxLayout()
button = QtGui.QPushButton('Get Value')
button.clicked.connect(self.someFunction)
layout.addWidget(button)
self.setLayout(layout)
def someFunction(self):
value = self.GetValueLineEdit()
if value :
# do something
def GetValueLineEdit(self):
class getValuePanel(QtGui.QDialog):
def __init__(self):
super(getValuePanel, self).__init__()
layout = QtGui.QHBoxLayout()
self.lineEdit = QtGui.QLineEdit('')
getValueButton = QtGui.QPushButton('Get Value')
getValueButton.clicked.connect(self.getValue)
layout.addWidget(self.lineEdit)
layout.addWidget(getValueButton)
self.setLayout(layout)
def getValue(self):
value = str(self.lineEdit.text())
getValuePanel.accept() #To Close the QDialog
return value
getValuePanel = getValuePanel()
getValuePanel.show()
pane = nuke.getPaneFor("Example.panel")
panels.registerWidgetAsPanel('Example', 'Example',"", True).addToPane(pane)
Thanks a lot,