I'm learning PyQt / Qt and I am facing a basic problem. I want to make a child class that inherits from QWidget but for some reason it does not show.
For trouble shooting, I've used a simple dummy child class.
from PyQt6.QtWidgets import QWidget, QApplication,QMainWindow, QLabel
import sys
class TestWidget(QWidget):
pass
class TestLabel(QLabel):
pass
app = QApplication(sys.argv)
w = QMainWindow()
w.resize(500,500)
w.setStyleSheet('background-color: white;')
w.show()
#frame = QWidget(w) # SHOWS
frame = TestWidget(w) # DOES NOT SHOW
#frame = TestLabel(w) # SHOWS
frame.resize(200,200)
frame.setStyleSheet('background-color: red;')
frame.show()
app.exec()
In the code sample I have tested the following scenarios (by commenting out the other two options). The expected result is a red rectangle in the upper left corner:
- Using a simple QWidget; it shows
- Using a dummy child class of QWidget; it does not show
- Using a dummy child class of QLabel; it shows
The code is really simple so I'm struggling to understand what's going on.
I'm using Python 3.11 on Mac OS Ventura (Apple Silicon).
Any ideas?