Results 1 to 9 of 9

Thread: QtDesigner and Python

  1. #1
    Join Date
    Sep 2012
    Location
    Ankara
    Posts
    15
    Thanks
    3
    Qt products
    Platforms
    Unix/X11

    Angry QtDesigner and Python

    Hi everyone.
    I have two problems with QtDesigner.
    I'm using QtDesigner and converting file to PyQt with this code:
    Qt Code:
    1. pyuic4 -x [input] -o [output]
    To copy to clipboard, switch view to plain text mode 

    I'm adding functions to output file and make it do something.

    For example I have a graphicsView and a line Edit and two buttons.
    Ok. When you clicked on first button a dialog open file appears and let you select an image file to view on graphicsview.
    I want fill Line Edit with my name when second button clicked. But I want to send my name as a parameter to class.
    But I can't display image and sent parameter to a class. This is my code:

    Qt Code:
    1. # -*- coding: utf-8 -*-
    2.  
    3. # Form implementation generated from reading ui file 'exa.ui'
    4. #
    5. # Created: Sun Sep 23 11:25:27 2012
    6. # by: PyQt4 UI code generator 4.7.4
    7. #
    8. # WARNING! All changes made in this file will be lost!
    9.  
    10. from PyQt4 import QtCore, QtGui
    11.  
    12. class Ui_Form(object):
    13. def setupUi(self, Form):
    14. Form.setObjectName("Form")
    15. Form.resize(665, 575)
    16. self.pushButton = QtGui.QPushButton(Form)
    17. self.pushButton.setGeometry(QtCore.QRect(30, 530, 88, 27))
    18. self.pushButton.setObjectName("pushButton")
    19. self.lineEdit = QtGui.QLineEdit(Form)
    20. self.lineEdit.setGeometry(QtCore.QRect(220, 530, 421, 27))
    21. self.lineEdit.setObjectName("lineEdit")
    22. self.graphicsView = QtGui.QGraphicsView(Form)
    23. self.graphicsView.setGeometry(QtCore.QRect(20, 10, 621, 451))
    24. self.graphicsView.setObjectName("graphicsView")
    25. self.pushButton_2 = QtGui.QPushButton(Form)
    26. self.pushButton_2.setGeometry(QtCore.QRect(550, 470, 88, 27))
    27. self.pushButton_2.setObjectName("pushButton_2")
    28.  
    29. self.retranslateUi(Form)
    30. QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.changeText)
    31. QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL("clicked()"), self.displayImage)
    32. QtCore.QMetaObject.connectSlotsByName(Form)
    33.  
    34. def retranslateUi(self, Form):
    35. Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
    36. self.pushButton.setText(QtGui.QApplication.translate("Form", "Change text", None, QtGui.QApplication.UnicodeUTF8))
    37. self.lineEdit.setText(QtGui.QApplication.translate("Form", "awdaddwa", None, QtGui.QApplication.UnicodeUTF8))
    38. self.pushButton_2.setText(QtGui.QApplication.translate("Form", "Add picture", None, QtGui.QApplication.UnicodeUTF8))
    39.  
    40. def displayImage(self):
    41. filename=QtGui.QFileDialog.getOpenFileName(Form,"ADd file...","./",("Image (*.gif *.jpeg *.jpg *.png)"))
    42. #Display image in GraphicsView I can't do this part.
    43.  
    44. def changeText(self):
    45. self.lineEdit.setText(QtGui.QApplication.translate("Form", "Muhammed SHEMUNI", None, QtGui.QApplication.UnicodeUTF8))
    46.  
    47. if __name__ == "__main__":
    48. import sys
    49. app = QtGui.QApplication(sys.argv)
    50. Form = QtGui.QWidget()
    51. ui = Ui_Form()
    52. ui.setupUi(Form)
    53. Form.show()
    54. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    Sorry for bad English.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtDesigner and Python

    Have a look at QGraphicsScene::addPixmap()
    By the way, do not change the file generated by pyuic. Instead subclass the class and add your code to your subclass.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    mshemuni (25th September 2012)

  4. #3
    Join Date
    Sep 2012
    Location
    Ankara
    Posts
    15
    Thanks
    3
    Qt products
    Platforms
    Unix/X11

    Default Re: QtDesigner and Python

    Quote Originally Posted by wysota View Post
    Have a look at QGraphicsScene::addPixmap()
    By the way, do not change the file generated by pyuic. Instead subclass the class and add your code to your subclass.
    Well. I'm a newbie.
    Can you fix my code and sen it back?
    So I can use it as a sample.
    I think there will be two files and I must import my code file to pyuic generated file ha? But how?

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QtDesigner and Python

    I think there will be two files and I must import my code file to pyuic generated file ha?
    I can't help you with Python code, but as Wysota said, don't touch the pyuic file. Import the pyuic generated file into *your* custom code file, not the other way around. This is exactly the same as C++ programmers do with the MOC- and UIC-generated files.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtDesigner and Python

    Quote Originally Posted by mshemuni View Post
    I think there will be two files and I must import my code file to pyuic generated file ha? But how?
    Most probably using the "import" statement
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #6
    Join Date
    Sep 2012
    Location
    Ankara
    Posts
    15
    Thanks
    3
    Qt products
    Platforms
    Unix/X11

    Default Re: QtDesigner and Python

    Quote Originally Posted by wysota View Post
    Most probably using the "import" statement
    What about triggers and getting parameters from functions?
    Please make a small, silly, pathetic example for me. (:

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtDesigner and Python

    Quote Originally Posted by mshemuni View Post
    What about triggers and getting parameters from functions?
    I have no idea what you mean.

    Please make a small, silly, pathetic example for me. (:
    See the attachment.
    Attached Files Attached Files
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    mshemuni (25th September 2012)

  10. #8
    Join Date
    Sep 2012
    Location
    Ankara
    Posts
    15
    Thanks
    3
    Qt products
    Platforms
    Unix/X11

    Default Re: QtDesigner and Python

    Quote Originally Posted by wysota View Post
    I have no idea what you mean.
    At first thank you very much for example.

    But I meant triggers like Onclick, OnMouseMove, OnMouseDown and bla bla.
    For example can you make a calculator that can print sum of two numbers.
    Something like this:
    But you said do not change pyuic4 generated file. How can I do the example above with your method?
    Last edited by mshemuni; 25th September 2012 at 09:02.

  11. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtDesigner and Python

    Quote Originally Posted by mshemuni View Post
    But I meant triggers like Onclick, OnMouseMove, OnMouseDown and bla bla.
    For example can you make a calculator that can print sum of two numbers.
    See attachment.
    Attached Files Attached Files
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. The following user says thank you to wysota for this useful post:

    mshemuni (25th September 2012)

Similar Threads

  1. Embedding PyQt4 into an Application running Python via Boost::Python
    By GreyHound in forum Installation and Deployment
    Replies: 1
    Last Post: 6th February 2012, 06:48
  2. Replies: 0
    Last Post: 8th April 2011, 20:10
  3. Python and QT
    By restrict9 in forum Newbie
    Replies: 1
    Last Post: 2nd January 2010, 16:47
  4. Python to C++
    By ComaWhite in forum General Programming
    Replies: 1
    Last Post: 15th March 2008, 23:05
  5. Qt, Python and pop-ups
    By bashamehboob in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2007, 19:33

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.