How to get value from QDialog using multiple class











up vote
1
down vote

favorite












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,










share|improve this question




























    up vote
    1
    down vote

    favorite












    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,










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      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,










      share|improve this question















      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,







      python pyside qdialog






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 6 at 19:35









      eyllanesc

      70.3k93052




      70.3k93052










      asked Nov 6 at 19:00









      Roman

      154




      154
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          First of all you do not create classes within other classes, it is considered a bad practice. On the other hand what returns a slot is not used since no one receives it, so what returns getValue will be lost, what you must do is that the clicked call accept closing the QDialog and after verifying that the dialogue has been accepted you just have to call getValue:



          class ValuePanel(QtGui.QDialog):
          def __init__(self):
          super(ValuePanel, self).__init__()
          self.lineEdit = QtGui.QLineEdit()
          getValueButton = QtGui.QPushButton('Get Value')
          getValueButton.clicked.connect(self.accept)

          layout = QtGui.QHBoxLayout(self)
          layout.addWidget(self.lineEdit)
          layout.addWidget(getValueButton)

          def getValue(self):
          value = str(self.lineEdit.text())
          return value

          class Example(QtGui.QWidget):
          def __init__(self):
          super(Example,self).__init__()
          button = QtGui.QPushButton('Get Value')
          button.clicked.connect(self.someFunction)

          layout = QtGui.QVBoxLayout(self)
          layout.addWidget(button)

          @QtCore.Slot()
          def someFunction(self):
          value_panel = ValuePanel()
          if value_panel.exec_() == QtGui.QDialog.Accepted:
          print(value_panel.getValue())





          share|improve this answer





















          • Awesome ! That does exactly what I was looking for. Thank you very much ! I will keep that in mind for the class.
            – Roman
            Nov 6 at 21:45











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53178290%2fhow-to-get-value-from-qdialog-using-multiple-class%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          First of all you do not create classes within other classes, it is considered a bad practice. On the other hand what returns a slot is not used since no one receives it, so what returns getValue will be lost, what you must do is that the clicked call accept closing the QDialog and after verifying that the dialogue has been accepted you just have to call getValue:



          class ValuePanel(QtGui.QDialog):
          def __init__(self):
          super(ValuePanel, self).__init__()
          self.lineEdit = QtGui.QLineEdit()
          getValueButton = QtGui.QPushButton('Get Value')
          getValueButton.clicked.connect(self.accept)

          layout = QtGui.QHBoxLayout(self)
          layout.addWidget(self.lineEdit)
          layout.addWidget(getValueButton)

          def getValue(self):
          value = str(self.lineEdit.text())
          return value

          class Example(QtGui.QWidget):
          def __init__(self):
          super(Example,self).__init__()
          button = QtGui.QPushButton('Get Value')
          button.clicked.connect(self.someFunction)

          layout = QtGui.QVBoxLayout(self)
          layout.addWidget(button)

          @QtCore.Slot()
          def someFunction(self):
          value_panel = ValuePanel()
          if value_panel.exec_() == QtGui.QDialog.Accepted:
          print(value_panel.getValue())





          share|improve this answer





















          • Awesome ! That does exactly what I was looking for. Thank you very much ! I will keep that in mind for the class.
            – Roman
            Nov 6 at 21:45















          up vote
          1
          down vote



          accepted










          First of all you do not create classes within other classes, it is considered a bad practice. On the other hand what returns a slot is not used since no one receives it, so what returns getValue will be lost, what you must do is that the clicked call accept closing the QDialog and after verifying that the dialogue has been accepted you just have to call getValue:



          class ValuePanel(QtGui.QDialog):
          def __init__(self):
          super(ValuePanel, self).__init__()
          self.lineEdit = QtGui.QLineEdit()
          getValueButton = QtGui.QPushButton('Get Value')
          getValueButton.clicked.connect(self.accept)

          layout = QtGui.QHBoxLayout(self)
          layout.addWidget(self.lineEdit)
          layout.addWidget(getValueButton)

          def getValue(self):
          value = str(self.lineEdit.text())
          return value

          class Example(QtGui.QWidget):
          def __init__(self):
          super(Example,self).__init__()
          button = QtGui.QPushButton('Get Value')
          button.clicked.connect(self.someFunction)

          layout = QtGui.QVBoxLayout(self)
          layout.addWidget(button)

          @QtCore.Slot()
          def someFunction(self):
          value_panel = ValuePanel()
          if value_panel.exec_() == QtGui.QDialog.Accepted:
          print(value_panel.getValue())





          share|improve this answer





















          • Awesome ! That does exactly what I was looking for. Thank you very much ! I will keep that in mind for the class.
            – Roman
            Nov 6 at 21:45













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          First of all you do not create classes within other classes, it is considered a bad practice. On the other hand what returns a slot is not used since no one receives it, so what returns getValue will be lost, what you must do is that the clicked call accept closing the QDialog and after verifying that the dialogue has been accepted you just have to call getValue:



          class ValuePanel(QtGui.QDialog):
          def __init__(self):
          super(ValuePanel, self).__init__()
          self.lineEdit = QtGui.QLineEdit()
          getValueButton = QtGui.QPushButton('Get Value')
          getValueButton.clicked.connect(self.accept)

          layout = QtGui.QHBoxLayout(self)
          layout.addWidget(self.lineEdit)
          layout.addWidget(getValueButton)

          def getValue(self):
          value = str(self.lineEdit.text())
          return value

          class Example(QtGui.QWidget):
          def __init__(self):
          super(Example,self).__init__()
          button = QtGui.QPushButton('Get Value')
          button.clicked.connect(self.someFunction)

          layout = QtGui.QVBoxLayout(self)
          layout.addWidget(button)

          @QtCore.Slot()
          def someFunction(self):
          value_panel = ValuePanel()
          if value_panel.exec_() == QtGui.QDialog.Accepted:
          print(value_panel.getValue())





          share|improve this answer












          First of all you do not create classes within other classes, it is considered a bad practice. On the other hand what returns a slot is not used since no one receives it, so what returns getValue will be lost, what you must do is that the clicked call accept closing the QDialog and after verifying that the dialogue has been accepted you just have to call getValue:



          class ValuePanel(QtGui.QDialog):
          def __init__(self):
          super(ValuePanel, self).__init__()
          self.lineEdit = QtGui.QLineEdit()
          getValueButton = QtGui.QPushButton('Get Value')
          getValueButton.clicked.connect(self.accept)

          layout = QtGui.QHBoxLayout(self)
          layout.addWidget(self.lineEdit)
          layout.addWidget(getValueButton)

          def getValue(self):
          value = str(self.lineEdit.text())
          return value

          class Example(QtGui.QWidget):
          def __init__(self):
          super(Example,self).__init__()
          button = QtGui.QPushButton('Get Value')
          button.clicked.connect(self.someFunction)

          layout = QtGui.QVBoxLayout(self)
          layout.addWidget(button)

          @QtCore.Slot()
          def someFunction(self):
          value_panel = ValuePanel()
          if value_panel.exec_() == QtGui.QDialog.Accepted:
          print(value_panel.getValue())






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 6 at 19:45









          eyllanesc

          70.3k93052




          70.3k93052












          • Awesome ! That does exactly what I was looking for. Thank you very much ! I will keep that in mind for the class.
            – Roman
            Nov 6 at 21:45


















          • Awesome ! That does exactly what I was looking for. Thank you very much ! I will keep that in mind for the class.
            – Roman
            Nov 6 at 21:45
















          Awesome ! That does exactly what I was looking for. Thank you very much ! I will keep that in mind for the class.
          – Roman
          Nov 6 at 21:45




          Awesome ! That does exactly what I was looking for. Thank you very much ! I will keep that in mind for the class.
          – Roman
          Nov 6 at 21:45


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53178290%2fhow-to-get-value-from-qdialog-using-multiple-class%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine