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,
python pyside qdialog
add a comment |
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,
python pyside qdialog
add a comment |
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,
python pyside qdialog
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
python pyside qdialog
edited Nov 6 at 19:35
eyllanesc
70.3k93052
70.3k93052
asked Nov 6 at 19:00
Roman
154
154
add a comment |
add a comment |
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())
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
add a comment |
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())
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
add a comment |
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())
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
add a comment |
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())
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())
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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