I am loading a QMainWIndow base from a *.ui file. Also, i have a custom widget i want to place somewhere on the form. Currently i put in the .ui file an empty QVBoxLayout
named placeholder
, and in the QMainWindow subclass do self.placeholder.addWidget(my_custom_widget)
The only thing i don't like in this approach is that the empty layout does not have its own size. I can have a layout with one cell and with a dummy widget (QLabel
for example) with the size i want, and replace this widget and then add my custom widget, but the method seems too much for me.
What is your approach for such a task?
I am using Python (PyQt4)
Here is an easy little tutorial on how to promote a widget:
QWidget
in this case.MyWidget
MyWidget
is placed. Promote
. You are done promoting. QWidget
, it's MyWidget
instead.In the file at /path/to/MyWidget.py
I have a class named MyWidget
, and the content is something like this:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from PyQt4 import QtGui
class MyWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(MyWidget, self).__init__(parent)
self.labelHello = QtGui.QLabel(self)
self.labelHello.setText("This is My Widget")
self.layout = QtGui.QHBoxLayout(self)
self.layout.addWidget(self.labelHello)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With