复合窗口部件就是由两个或者多个其他窗口部件组合在一起的窗口部件。在大的工程项目中创建可重复使用的复合窗口部件能够节约大量时间。本文就是通过python3+PyQt5实现。
#!/usr/bin/env python3
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QApplication, QBoxLayout, QDialog,
QDialogButtonBox, QGridLayout, QLabel, QLineEdit, QTextEdit,
QVBoxLayout, QWidget)
LEFT, ABOVE = range(2)
class LabelledLineEdit(QWidget):
def __init__(self, labelText="", position=LEFT,
parent=None):
super(LabelledLineEdit, self).__init__(parent)
self.label = QLabel(labelText)
self.lineEdit = QLineEdit()
self.label.setBuddy(self.lineEdit)
layout = QBoxLayout(QBoxLayout.LeftToRight
if position == LEFT else QBoxLayout.TopToBottom)
layout.addWidget(self.label)
layout.addWidget(self.lineEdit)
self.setLayout(layout)
class LabelledTextEdit(QWidget):
def __init__(self, labelText="", position=LEFT,
parent=