0

When I click "View Code" in Qt Designer (PyQt4), it tries to show the C++ code.

So, the workaround is to run:

pyuic4.bat test.ui > test.py

to convert the file to .py.

Is there a way to execute the above workaround every time "View Code" is clicked or should I have to always perform it manually?

The answer by @WithMetta in the duplicate solved my problem.

adb16x
  • 658
  • 6
  • 24
  • PyQt4 is a library, not a program. What program are you talking about? Qt Designer? Qt Creator? – three_pineapples Sep 18 '15 at 08:27
  • Sorry, I meant Qt Designer. – adb16x Sep 18 '15 at 08:28
  • possible duplicate of [Using QTDesigner with PyQT and Python 2.6](http://stackoverflow.com/questions/2489643/using-qtdesigner-with-pyqt-and-python-2-6) – three_pineapples Sep 19 '15 at 02:03
  • 1
    Note that while the *accepted* answer in the flagged duplicate doesn't appear to answer the original question (either for the duplicate or this question), [this](http://stackoverflow.com/a/13461481/1994235) answer further down the page does. – three_pineapples Sep 19 '15 at 02:05

1 Answers1

3

I personally load those ui files on the fly without generating python code: something like this works for me:

import sys
from PyQt4 import QtCore,QtGui,uic
form_class, base_class = uic.loadUiType("unnamed.ui")

class MyWidget (QtGui.QWidget, form_class):
    def __init__(self,parent=None,selected=[],flag=0,*args):
        QtGui.QWidget.__init__(self,parent,*args)
        self.setupUi(self)
if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    form = MyWidget(None)
    form.show()
    app.exec_()
Oleg Gopkolov
  • 1,684
  • 10
  • 17