Hi
I am discovering Python3, written already a first tool with it and now “simply” want to make a GUI for it.
I have so start looking at pyQT, (pyQT4, I didn’t found any references for pyQT5, only C++ ones, no python.).
And I am struggling a bit for finding tutorials about pyQT4 in python3. They are often with python2.7 or using QTdesigner which is great but so limited I don’t understand how it can be useful (no spinners, no browser query and I don’t even thin how to make dynamic gui with that…)… But tutorials, or simple exemples about GUI scripting only with pyQT4, no QTdesigner, niet, nada.
I’d like to code my UI entirely in my IDE, in python3, just as I was doing with maxscript.
BUT, I can’t find simple sample, the ones I found are quite indigestible with bits of code all over the place and no coments anywhere explaining what does what.
I wonder if it is possible to have a layout similar to what I could do in MaxScript like :
a/ Declare my Rollout
b/ Declare my buttons (with groups and all which could be the same with the layout I can see in pyQT)
c/ Events
d/ Create dialog
the end.
And here’s a very very simple python code generated from QtDesigner (One button in one layout, that’s its.) :
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(400, 299)
self.horizontalLayout = QtGui.QHBoxLayout(Form)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.btn_TestButton001 = QtGui.QPushButton(Form)
self.btn_TestButton001.setObjectName(_fromUtf8("btn_TestButton001"))
self.verticalLayout.addWidget(self.btn_TestButton001)
self.horizontalLayout.addLayout(self.verticalLayout)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Image Cutter", None))
self.btn_TestButton001.setText(_translate("Form", "TestButton001", None))
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
Which is quite a mess to me and not readable (though I don’t have a problem reading code in general, but this one looks very filthy to me).
And now I wonder if it is : 1) because of the conversion from QTdesigner or 2) if it is a standard writing for a pyQT4 script.
In the first case if someone could point me to some properly written pyQT script (with nice coments and all) that would be great.
In the second case if someone could point me to some tutorial or samples with coments explaining this code that would save my day.
Or maybe it is simply best not coding in python and using a solution like QML ? In any case any advise is most welcom.
Many Thanks
Bloby