I'm still new to pyqt and trying to learn different things.
What I want is to create a custom Qt widget (using the Qt Creator) and have the result as a python (pyqt) class (I called it 'myCustomWidget') in its own module. Then when I want to add it under the parent widget 'parent_widget' just call myCustomWidget, something along the lines of self.my_widget = myCustomWidget(parent_widget)
IMPORTANT - myCustomWidget is an elaborate widget that contains several nested frames and buttons in various layouts.
IMPORTANT 2 - myCustomWidget is meant to be used an an 'overlay', a floating piece of UI that is not connected to any layout, so in my case the parent_widget is actually centralwidget.
What I tried I created a widgets application on Qt Creator, built the UI with it, Then convert the ui file into a python file. That py file starts with the following code:
class myCustomWidget(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1024, 768)
MainWindow.setStyleSheet("")
self.my_frame = QtWidgets.QWidget(MainWindow)
self.my_frame.setStyleSheet(...
...
(Note how it has no 'init' method but a setupUi method. That confused me a lot)
then I replaced it to be the following:
class myCustomWidget(QWidget):
def __init__(self, parent):
super(myCustomWidget, self).__init__(parent)
self.my_frame = QtWidgets.QWidget(parent)
self.my_frame.setStyleSheet("...
...
And then used it:
self.my_widget = myCustomWidget(centralwidget)
self.my_widget.move(QPoint(500, 500)) # Just to see where it gets and how to interact with it.
The problem is, of course, that none of it work. I do see on the top left corner of my main window, a tiny something that obviously has the components of myCustomWidget only without the proportions.
Thanks for your help!