Results 1 to 10 of 10

Thread: PyQT copy text from form1 to form2

  1. #1
    Join Date
    Oct 2016
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default PyQT copy text from form1 to form2

    Dear Friends. I wrote a program that have Form and Form2 called V1. V1 will show after cliked button in Form1.
    In V1 I have a LineEdit and button. When i wrote something in LineEdit in V1 I want send this text to LineEdit in Form1.

    Qt Code:
    1. from PyQt4 import QtCore, QtGui
    2. from V1 import Ui_V1
    3.  
    4.  
    5. try:
    6. _fromUtf8 = QtCore.QString.fromUtf8
    7. except AttributeError:
    8. def _fromUtf8(s):
    9. return s
    10.  
    11. try:
    12. _encoding = QtGui.QApplication.UnicodeUTF8
    13. def _translate(context, text, disambig):
    14. return QtGui.QApplication.translate(context, text, disambig, _encoding)
    15. except AttributeError:
    16. def _translate(context, text, disambig):
    17. return QtGui.QApplication.translate(context, text, disambig)
    18.  
    19. # V1 window
    20. class Ui_V1(object):
    21. def setupUi(self, V1):
    22. V1.setObjectName(_fromUtf8("V1"))
    23. V1.resize(400, 300)
    24. self.label = QtGui.QLabel(V1)
    25. ...
    26. self.pushButton.setText(_translate("V1", "Wyslij", None))
    27. self.pushButton_2.setText(_translate("V1", "Wyslij", None))
    28. self.pushButton.clicked.connect(lambda: self.wyslij())
    29.  
    30. def wyslij(self):
    31. self.lineEdit.setText(self.Ui_Form.lineEdit_11.text())
    32.  
    33.  
    34.  
    35.  
    36. # Main window!
    37. class Ui_Form(object):
    38. def setupUi(self, Form):
    39. Form.setObjectName(_fromUtf8("Form"))
    40. Form.resize(728, 601)
    41. Form.setMinimumSize(QtCore.QSize(728, 601))
    42. self.label_6 = QtGui.QLabel(Form)
    43. self.label_6.setGeometry(QtCore.QRect(169, 3, 401, 41))
    44. self.label_6.setObjectName(_fromUtf8("label_6"))...
    45.  
    46.  
    47. def retranslateUi(self, Form):
    48. Form.setWindowTitle(_translate("Form", "Form", None))
    49. self.label_6.setText(_translate("Form", "<html><head/><body><p><span style=\" font-size:16pt; font-weight:600;\">TYGODNIOWA KONTROLA JAKOSCI</span></p></body></html>", None))
    50. self.label_8.setText(_translate("Form", "(dd-mm-rrrr)", None))...
    51.  
    52. self.pushButton_2.clicked.connect(lambda: self.zapis_tyg()) # Do zapisu do tyg formularza
    53. self.pushButton_5.clicked.connect(lambda: self.openV1()) # v1 window
    54.  
    55.  
    56. #zapis do pliku formularza tyg
    57. def zapis_tyg(self): # ZAPIS DO FORMULARZ TYGODNIOWEGO
    58. s = ""
    59. seq = (self.comboBox_6.currentText(), ".txt"); # This is sequence of strings. laczenie aby nazywał pliki wzaleznosci od aparatu
    60. a= s.join( seq )
    61. text_file = open( a , "a")
    62. text_file.write(self.lineEdit.text()+ "\t" ) #data
    63. text_file.write(self.lineEdit_2.text()+ "\t" ) #osoba
    64. text_file.write(self.comboBox_6.currentText() + "\t" ) #aparat
    65. text_file.write(self.comboBox.currentText() + "\t" ) #AKCESORIUM
    66. text_file.write(self.comboBox_2.currentText() + "\t" ) #ZAB ANTYK
    67. text_file.write(self.comboBox_3.currentText() + "\t" ) #iZO
    68. text_file.write(self.comboBox_4.currentText() + "\t" )# CENTRQTOR
    69. text_file.write(self.comboBox_5.currentText() + "\t" )# TELEMETR
    70. text_file.write(self.textEdit.toPlainText()+ "\n" ) # KOM MECH
    71. text_file.close()
    72.  
    73. #function to show a new form
    74. def openV1(self):
    75. self.V1Window=QtGui.QMainWindow()
    76. self.ui= Ui_V1()
    77. self.ui.setupUi(self.V1Window)
    78. self.V1Window.show()
    To copy to clipboard, switch view to plain text mode 

    I had an error:

    'Ui_V1' object has no attribute 'Ui_Form'
    Where is the problem?
    Thank you

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PyQT copy text from form1 to form2

    First, this looks like you have edited the generated class instead of just using it.

    Second, as Python tells you, your Ui_V1 class does not have any member called Ui_Form.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2016
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: PyQT copy text from form1 to form2

    Thanks for reply

    I am beginner in python and in GUI so that why i am writinig in code in this class instead of creating second file only with functions.

    so how to conect Ui_V1 wiht Ui_Form ? Because i coonected button with Ui_V1 but i cant connect button with Labels...

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PyQT copy text from form1 to form2

    If you want to access "self.Ui_Form" then you need to initizalize this.

    Something like
    Qt Code:
    1. self.Ui_Form = Ui_Form()
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. #5
    Join Date
    Oct 2016
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: PyQT copy text from form1 to form2

    Ok so I have done it :

    def wyslij(self):
    self.kopiaWindow=QtGui.QMainWindow()
    self.Ui_Form=Ui_Form()
    self.Ui_Form.lineEdit.text()=self.lineEdit.text()
    and i have an error:
    SyntaxError: can't assign to function call
    thanks.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PyQT copy text from form1 to form2

    Yes, last line of your new code.

    You are trying to assign to the function text()
    You probably want to assign to the property text instead.

    Cheers,
    _

  7. #7
    Join Date
    Oct 2016
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: PyQT copy text from form1 to form2

    So how i cantransfer text from lineEdit (V1 Form) to lineEdit ( Ui_form)?

    Thanks

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PyQT copy text from form1 to form2

    Either by assiging to the target's text property or by calling the target's setText function.

    Cheers,
    _

  9. #9
    Join Date
    Oct 2016
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: PyQT copy text from form1 to form2

    could you show me an example how to do this?
    Thanks

    something like this?
    self.Ui_Form.lineEdit.text(self.lineEdit.text())
    Error:
    AttributeError: 'Ui_Form' object has no attribute 'lineEdit'
    This error is showing when I paste V1 class in MainFile.py but when I separate in two files (of course with import V1/Import MainFile)

    self.Ui_Form=Ui_Form()
    NameError: name 'Ui_Form' is not defined
    thanks
    Last edited by logilink; 10th October 2016 at 11:14.

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PyQT copy text from form1 to form2

    Quote Originally Posted by logilink View Post
    could you show me an example how to do this?
    Maybe you should consider doing a Python tutorial first if you are unclear about assignments or method calls.

    Quote Originally Posted by logilink View Post
    something like this?
    No, QLineEdit does not have a method called "text" that also has arguments.
    Why would you even try that?

    Quote Originally Posted by logilink View Post
    Error:
    Which is a different error all together, you are trying to access an object that doesn't exist.
    Python is sometimes doing things that are automagically correct, but even Python can't magically create objects.

    Cheers,
    _

Similar Threads

  1. text from form1 to form2
    By vanduongbk in forum Newbie
    Replies: 4
    Last Post: 17th June 2013, 09:22
  2. show form2 from form1( form1 will hide)
    By jindoniit in forum Newbie
    Replies: 1
    Last Post: 5th July 2011, 09:18
  3. transfer graphicsscene on form1 to graphicsscene on form2
    By rogerholmes in forum Qt Programming
    Replies: 2
    Last Post: 25th September 2009, 20:37
  4. Replies: 1
    Last Post: 7th November 2007, 08:39
  5. accessing form1's objects from form2
    By Philip_Anselmo in forum Newbie
    Replies: 5
    Last Post: 4th May 2006, 22:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.