0

I made a gui using Pyqt earlier. I did all the coding on the terminal in Linux. Now I am going to make a big project in Pyqt.
Is there any sdk which will help me to overcome the coding part, so I can just drag and drop the items? I know about qt designer, but I don't know how I should write and integrate it with Python.

Do you have suggestions on what program to use for this?

2 Answers 2

3

Qt Designer when coupled with PyQt4 is usually used only for the layout process, as opposed to defining signals, buddies, etc. You perform the visual layout of your widgets, and save the .ui file.

Using pyuic4, you can then compile the .ui -> .py, and import that into your coded project.

Though there are probably 3 different approaches to using the UI at this point, what I typically do is multiple inheritance. If class MyMainWindow is meant to be a QMainWindow, then I inherit my class from QMainWindow, and the UI class.

Something like this...

pyuic4 myMainWindow.ui -o myMainWindowUI.py

main.py

from PyQt4 import QtGui
from myMainWindowUI import Ui_MainWindow

class MyMainWindow(QtGui.QMainWindow, Ui_MainWindow):

    def __init__(self, *args, **kwargs)
        super(MyMainWindow, self).__init__(*args, **kwargs)
        self.setupUi(self)

The setupUi method applies your entire UI design to the class and you can now access all of the widgets you designed by their object names.

win = MyMainWindow()
print win.listWidget
print win.button1
win.show()
Sign up to request clarification or add additional context in comments.

4 Comments

Hi, lets say that I have another class for another window. How can I access the widgets in the UI_MainWindow file?
@dnth Do you mean you have a second window class? If you have another window instance, it should not be directly accessing widgets of a different class. Can you be more specific?
I meant to ask this question stackoverflow.com/questions/33056555/…
@dnth - I will just try and answer on your question
1

See Creating interfaces visually with designer

if using pyqt4 use pyuic4

if using pyside use pyside-uic

These compile the output from QTDesigner into a python file.

You can google you way to usage of these command line tools but Riverbank is usually a good reference

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.