
- PyQt - Home
- PyQt - Introduction
- PyQt - Environment
- PyQt - Hello World
- PyQt - Major Classes
- PyQt - Using Qt Designer
- PyQt - Meta Objects
- PyQt Signals & Slots
- PyQt - Signals and Slots
- PyQt - Support and Signals
- PyQt - Unbound and Bound Signals
- PyQt - New Signals with PyQtSignal
- PyQt - Connecting, Disconnecting, & Emitting Signals
- PyQt - Slot decorator
- PyQt - Slot Connection
- PyQt Layouts
- PyQt - Layout Management
- PyQt - QBoxLayout
- PyQt - QGridLayout
- PyQt - QFormLayout
- PyQt - QHBoxLayout
- PyQt - QVBoxLayout
- PyQt - QStackedLayout
- PyQt - QGraphicsGridLayout
- PyQt - QGraphicsAnchorLayout
- PyQt - QGraphicsLayout
- PyQt - QGraphicsLinearLayout
- PyQt Basic Widgets
- PyQt - Basic Widgets
- PyQt - Qlabel Widget
- PyQt - QLineEdit Widget
- PyQt - QPushButton Widget
- PyQt - QRadioButton Widget
- PyQt - QCheckBox Widget
- PyQt - QComboBox Widget
- PyQt - QSpinBox Widget
- PyQt - QMessageBox
- PyQt - QDialogButtonBox Widget
- PyQt - QFontComboBox Widget
- PyQt - QDoubleSpinBox Widget
- PyQt - QToolBox Widget
- PyQt - QMenuBar, QMenu & Qaction Widgets
- PyQt - QToolTip
- PyQt - QInputDialog Widget
- PyQt - QFontDialog Widget
- PyQt - QDialog Widget
- PyQt - QFileDialog Widget
- PyQt - QTab Widget
- PyQt - QSplitter Widget
- PyQt - QDock Widget
- PyQt - QStatusBar Widget
- PyQt - QTabBar
- PyQt - QList Widget
- PyQt - QScrollBar Widget
- PyQt - QProgressBar
- PyQt - QCalendar Widget
- PyQt - QMessageBox Widget
- PyQt - QPlainTextEdit
- PyQt - QDateEdit
- PyQt - QDateTimeEdit
- PyQt - QTimeEdit
- PyQt - QTextEdit
- PyQt - QTextBrowser
- PyQt - QScrollArea
- PyQt - Drag and Drop
- PyQt - Multiple Document Interface
- PyQt - QDialog Class
- PyQt Views
- PyQt - QColumnView
- PyQt - QTableView
- PyQt Drawing API
- PyQt - Drawing API
- PyQt - Drawing a Line
- PyQt - Drawing a Rectangle
- PyQt - Drawing a Triangle
- PyQt - Drawing a Circle
- PyQt - Drawing a Ellipse
- PyQt - Drawing a Polygon
- PyQt - Geometric Transformation
- PyQt - Drawing Effect
- PyQt Groups
- PyQt - QButtonGroup
- PyQt - QGroupBox
- PyQt Effects
- PyQt - Effects
- PyQt - Opacity Effect
- PyQt - QGraphicsBlur Effect
- PyQt - QGraphicsColorize Effect
- PyQt - QGraphicsDropShadow Effect
- PyQt Events
- PyQt - Event Handling
- PyQt - File Open Event
- PyQt - Action Event
- PyQt - Hide Event
- PyQt - Resize Event
- PyQt Database
- PyQt - Database Handling
- PyQt Essentials
- PyQt - BrushStyle Constants
- PyQt - QClipboard
- PyQt - QPixmap Class
- PyQt Useful Resources
- PyQt - Quick Guide
- PyQt - Useful Resources
- PyQt - Discussion
PyQt - QGraphicsLinearLayout
In the fast-paced world of building software, desktop applications that have graphical user interfaces (GUIs) are very important. These applications let users interact with software running on their own computers using an interface that is both interactive and visually appealing.
QGraphicsLinearLayout allows you to arrange widgets within Graphics View either horizontally or vertically.
QGraphicsLinearLayout is a layout tool within Qt Widgets that organizes widgets in the Graphics View framework. It arranges widgets horizontally (default) or vertically (set by setOrientation(Qt.Vertical)). To use QGraphicsLinearLayout, create an instance, optionally with a parent widget, and add widgets and layouts using addItem(). The layout takes ownership of added items. For items inheriting from QGraphicsItem (e.g., QGraphicsWidget), consider setOwnedByLayout() to manage ownership.
Example
In the following example, we create a simple PyQt application with a yellow background window using QGraphicsLinearLayout class and its method.
import sys from PyQt6.QtCore import Qt from PyQt6.QtGui import QPalette, QColor from PyQt6.QtWidgets import QApplication, QGraphicsView, QGraphicsScene, QGraphicsLinearLayout, QGraphicsWidget, QMainWindow def create_layout(): # Create a QGraphicsLinearLayout with vertical orientation layout = QGraphicsLinearLayout(Qt.Orientation.Vertical) # Create a QGraphicsWidget to hold the layout container_widget = QGraphicsWidget() # Add the layout to the container widget container_widget.setLayout(layout) return container_widget if __name__ == "__main__": app = QApplication(sys.argv) window = QMainWindow() # Create a QGraphicsView and set the scene view = QGraphicsView() scene = QGraphicsScene() view.setScene(scene) # Add the layout to the scene layout_widget = create_layout() scene.addItem(layout_widget) # Set the background color of the window palette = window.palette() # Set your desired color palette.setColor(QPalette.ColorRole.Window, QColor(255, 255, 0)) window.setPalette(palette) # Adjust the window size window.setGeometry(100, 100, 400, 200) window.show() sys.exit(app.exec())
Output
The above code produces the following output −
