PDA

View Full Version : Probelm With QInputDialog...



mishra.rakesh510
31st January 2014, 08:59
here is my code..

import sys
from PySide import QtGui


class Example(QtGui.QWidget):

def __init__(self):
super(Example, self).__init__()

self.initUI()

def initUI(self):

self.btn = QtGui.QPushButton('Dialog', self)
self.btn.move(20, 20)
self.btn.clicked.connect(self.showDialog)

self.le = QtGui.QLineEdit(self)
self.le.move(130, 22)

self.setGeometry(300, 300, 290, 150)
self.setWindowTitle('Input dialog')
self.show()

def showDialog(self):
dialog=QtGui.QInputDialog()
#dialog.setComboBoxItems(["a",'b','bcd'])
#dialog.textValueChanged.connect(self.fun)
dialog.setLabelText("asdasd")

dialog.show()

dialog.textValueChanged.connect(self.fun)
text, ok = dialog.getText(self, 'Input Dialog', 'Project Already Exist:')

if ok:
self.le.setText(str(text))
def fun(self,name):
print "fun is callling",name

def main():

app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())


if __name__ == '__main__':
main()


but it creates two dialog boxes one is from dialog=QtGui.QInputDialog()
and another one comes from
text, ok = dialog.getText(self, 'Input Dialog', 'Project Already Exist:')

i want to create a dialogbox and has a "textValueChanged" signal whenver text change it call fun slot and once i pressed on button it should
save in text, ok variable
Could u please help me to find the solution

Thanks in advance
Rakesh

anda_skoa
31st January 2014, 10:25
QInputDialog::getText() is a convenience function that created and runs a QInputDialog set up for text input.

You can see this in the C++ documentation because getText() is a static method (can be called without an object of QInputDialog) and it it called getSomething(), which in Qt is a very striong indicator that it is (a) static and (b) a helper/convenience function.

You can either use getText() or create the dialog instance yourself and use setInputMode() to get the text input version.

Cheers,
_