E4 - layouts
- the four basic layout types:
| layout | behavior |
|---|---|
| QHBoxLayout | linear horizontal layout |
| QVBoxLayout | linear vertical layout |
| QGridLayout | in indexable grid xxy |
| QStackedLayout | stacked (z) in front of one another |

image: Python GUIs
import sys
from PyQt.QtWidgets import QWidget
from PyQt6.QtGui import QColor, QPalette
class Color(QWidget):
def __init__(self, color):
super().__init__()
self.setAutoFillBackground(True)
palette = self.palette()
palette.setColor(QPalette.ColorRole.Window, QColor(color))
self.setPalette(palette)
import sys
- this creates a widget subclass that creates a solid-filled widget as follows:
Color('red
ffrom PyQt6.QtWidgets import QApplication, QMainWindow, QTabWidget
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("My App")
tabs = QTabWidget()
tabs.setTabPosition(QTabWidget.TabPosition.West)
tabs.setMovable(True)
for color in ["red", "green", "blue", "yellow"]:
tabs.addTab(Color(color), color)
self.setCentralWidget(tabs)
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()
- this creates a layout with tabs on the left that change the color of the widget when clicked
