I read, test and understand a lot of examples for usage of QWidgets from Qt designer, which are promoted to PyQt5. Nevertheless I am not able to deal with a simple example for my own.
Beneath I show my code, which is not working and try to explain.
in Qt desginer i create a simple QMainWindow, named standardized as MainWindow
Within I create a single label QLabel. This I promote to class "neuLabel" and name it labelqt. The window with, Add , the header neulabel.h and promote --> everything is fine.
I understand, that I have to write code for the class neuLabel. But: WHERE to do it?
With very simple example I tried it like this:
from PyQt5 import QtWidgets, uic
import sys
uifile_1 = 'testpromote.ui'
form_1, base_1 = uic.loadUiType(uifile_1)
class neuLabel(QLabel, QPixmap):
def __init__(self,title,pixmap,parent):
super().__init__(title,parent)
self.setAcceptDrops(True)
def mousePressEvent(self, e):
QLabel.mousePressEvent(self, e)
if e.button() == QtCore.Qt.LeftButton:
print('press')
class myApp(base_1, form_1):
def __init__(self):
super(base_1,self).__init__()
self.setupUi(self)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = myApp() #Dialog()
ex.show()
sys.exit(app.exec_())
The error is like this
Traceback (most recent call last):
File "/home/jf/PycharmProjects/myMuhaInp/testpromote.py", line 5, in <module>
form_1, base_1 = uic.loadUiType(uifile_1)
File "/usr/lib/python3/dist-packages/PyQt5/uic/__init__.py", line 201, in loadUiType
exec(code_string.getvalue(), ui_globals)
File "<string>", line 37, in <module>
ModuleNotFoundError: No module named 'neulabel'
I really don't understand, WHERE to code the class neulabel (and I really tried a lot of examples. (In no example, I found, is the promotion of a single QWidget)