42052

Can't start designed pyQt application

I have just designed my application inside pyQt Designer 5, generated my main.ui to main.py and my assets.qrc to assets_rc.py. No errors, when I now run main.py from my terminal nothing happends. Have I missed a step? Am I supposed to edit my main.py file now?

Cheers!

Python 3.3.0 pyQT 5

Answer1:

This is for PyQt4, but should be the same for PyQt5.

Let's say your ui is called "mainwindow.ui". Compile this with pyuic4 into "mainWindowUi.py" (or whatever, just stick to the name).

Now create a file "mainWindow.py" with more or less this content:

from PyQt4 import QtGui from mainWindowUi import Ui_MainWindow #same name as appears in mainWindowUi.py class MainWindow (QtGui.QMainWindow): #Or wherever you are inheriting from def __init__ (self, parent = None): super (MainWindow, self).__init__ () self.ui = Ui_MainWindow () #same name as appears in mainWindowUi.py self.ui.setupUi (self) #implement slots and signals and other funny things

Now create a file "program.py" with more or less this content:

#! /usr/bin/python3.3 import sys from PyQt4 import QtGui from mainWindow import MainWindow def main(): app = QtGui.QApplication (sys.argv) m = MainWindow () m.show () sys.exit (app.exec_ () ) if __name__ == '__main__': main ()

Run the program.py file. This is more or less the skeleton of a Qt application.

Recommend

  • python - format float to decimal in pyQt
  • How can I query asynchronously via a QSqlQueryModel?
  • Qt5 Matplotlib Designer Plugin
  • Importing matplotlib.pyplot fails in PyCharm due to AttributeError: module 'PyQt5.QtGui' h
  • Disabling QComboBox in pyqt
  • PyQT how to make a QEvent.Enter on QPushbutton?
  • VTK with Qt5 - Timer stops running when window is interacted with
  • Checking QValidator's state
  • Issue with fitInView of QGraphicsView when ItemIgnoresTransformations is on
  • reading pyqt stylesheet from external qss file
  • “Module use of python34.dll conflicts with this version of Python”
  • How to have a QTextBrowser to display contents of a QTextEdit?
  • How to fetch the entry text on a different window?
  • QStandardItemModel::removeRows() does not work in my use case
  • change volume of mp3 playing via wmplib in c#
  • How to reference a widget inside a specific tab of a QTabWidget?
  • Objective C difference between self.variable and variable assignments
  • How to test labels in QTP
  • Vertical alignment of float:left div's
  • sending email using “bcc” without “to” in java application
  • Random access image (picture) file
  • pymongo replication secondary readreference not work
  • import scipy.sparse failed
  • During installation of Django, why do I keep getting ImportError: No module named django?
  • where do I find the xml.dom python package for the python-2.6.0-8.9.28 and I have a suse/x86_64 vers
  • Python pickle not one-to-one: different pickles give same object
  • Adjust width of select element according to selected option's width
  • Use of this Javascript
  • Fetching methods from BroadcastReceiver to update UI
  • Symfony2: How to get request parameter
  • Why winpcap requires both .lib and .dll to run?
  • GridView Sorting works once only
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • WPF Applying a trigger on binding failure
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How to set the response of a form post action to a iframe source?
  • coudnt use logback because of log4j
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • unknown Exception android