not sure I am on the right section in the forum
I am lost in GUI creation, my problem is that I don't understand classes and OOP in general I suppose.
I followed the wiki tutorial for GUI creation with PySide, they create the GUI with Qt, and then translate the .ui file to .py, or they don't translate it and load it.
I want this second approach (load directly the .ui), and try a very simple thing: Enter 3 values and make a simple operation by clicking a button. If that works, the core thing is OK and I can make more complicated stuff.
The GUI looks like this:
and my .py file like this:
Code: Select all
from PySide import QtCore, QtGui, QtUiTools
# path to .ui
path_to_ui = r"C:\Users\Lilian\AppData\Roaming\FreeCAD\Macro\testUI.ui"
class MyButtons(QtGui.QDialog):
def __init__(self, MainWindow):
super(MyButtons, self).__init__()
self.window = MainWindow
# load .ui
loader = QtUiTools.QUiLoader()
uifile = QtCore.QFile(path_to_ui)
uifile.open(QtCore.QFile.ReadOnly)
self.ui = loader.load(uifile, None)
uifile.close()
self.ui.button_main_dimensions.clicked.connect(self.calc_nq()) #connection radioButton
def calc_nq(self):
# calculate the specific speed and writes the result in the label
# get entries
N = self.ui.doubleSpinBox_N.value()
Q = self.ui.doubleSpinBox_Q.value()
H = self.ui.doubleSpinBox_H.value()
nq = N*Q**0.5/H**0.75
self.ui.label_value_nq.setText(str(round(nq, 2)))
MainWindow = QtGui.QMainWindow()
ui = MyButtons(MainWindow)
MainWindow.show()
I bet the solution is simple though
I join the .ui file also if you wish to try that.
Lookid_.
OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.21125 (Git)
Build type: Release
Branch: master
Hash: 40600a55c2fe71ff589be677f6e427ccc937d003
Python version: 3.8.2
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United Kingdom (en_GB)