PyQt5中布局内的控件如何充满布局?

PyQt5中布局内的控件如何充满布局?
如图,PyQt5中布局内的控件如何充满布局?

class CodeVersionDlg(QDialog):

def __init__(self, parent=None):

super(CodeVersionDlg, self).__init__(parent)

windowFlag = Qt.Dialog;

windowFlag |= Qt.WindowMinimizeButtonHint;

windowFlag |= Qt.WindowMaximizeButtonHint;

windowFlag |= Qt.WindowCloseButtonHint;

self.setWindowFlags(windowFlag);

self.CodetxtPlainTextEdit = QPlainTextEdit()

self.CodetxtPlainTextEdit.setContextMenuPolicy(Qt.CustomContextMenu)

self.CodetxtPlainTextEdit.customContextMenuRequested[QPoint].connect(self.generateMenu4)

self.CodeversiontxtPlainTextEdit = QPlainTextEdit()

self.tableViewnew=QTableView()

self.model=QStandardItemModel(6,4)

self.tableViewnew.setModel(self.model)

self.tableViewnew.setColumnWidth(0,350)

tabWidget = QTabWidget()

CodetxtWidget = QWidget()

CodetxtLayout = QGridLayout()

CodetxtLayout.addWidget(self.CodetxtPlainTextEdit, 1, 0)

CodetxtLayout.addWidget(self.tableViewnew, 2, 0)

CodetxtWidget.setLayout(CodetxtLayout)

tabWidget.addTab(CodetxtWidget, "A")

self.model2=QStandardItemModel(4,3)

#设置水平方向四个头标签文本内容

self.model2.setHorizontalHeaderLabels(['old version','newer version','append'])

self.btn3 = QPushButton("append newer")

#实例化表格视图,设置模型为自定义的模型

self.tableViewnew2=QTableView()

self.tableViewnew2.setModel(self.model2)

self.tableViewnew2.setColumnWidth(0,32)

self.tableViewnew2.setColumnWidth(1,500)

self.tableViewnew2.setColumnWidth(2,500)

#self.tableViewnew2.setSectionResizeMode(QHeaderView.Stretch)

self.tableViewnew2.setContextMenuPolicy(Qt.CustomContextMenu)

newWidget = QWidget()

newLayout = QGridLayout()

newLayout.addWidget(self.tableViewnew2, 1, 0)

newLayout.addWidget(self.btn3)

newWidget.setLayout(newLayout)

tabWidget.addTab(newWidget, "B")

self.btn4 = QPushButton("modify older text")

self.btn5 = QPushButton("err code text2clip")

self.btn5.setToolTip('拷贝到剪切板')

self.tableViewOld=QTableView()

self.model3=QStandardItemModel(3,3)

self.tableViewOld.setModel(self.model3)

self.tableViewOld.setColumnWidth(0,32)

self.tableViewOld.setColumnWidth(1,500)

self.tableViewOld.setColumnWidth(2,500)

self.tableViewOld.setContextMenuPolicy(Qt.CustomContextMenu)

checkWidget = QWidget()

checkLayout = QGridLayout()

checkLayout.addWidget(self.tableViewOld, 1, 0,1,2)

checkLayout.addWidget(self.btn4,2,0)

checkLayout.addWidget(self.btn5,2,1)

checkWidget.setLayout(checkLayout)

tabWidget.addTab(checkWidget, "C")

self.tableViewIn=QTableView()

self.model4=QStandardItemModel(3,1)

self.tableViewIn.setModel(self.model4)

self.tableViewIn.setColumnWidth(0,500)

inWidget = QWidget()

inLayout = QGridLayout()

inLayout.addWidget(self.tableViewIn, 1, 0,1,2)

inWidget.setLayout(inLayout)

tabWidget.addTab(inWidget, "D")

layout = QVBoxLayout()

layout.addWidget(tabWidget)

self.setLayout(layout)

self.tableViewIn.setContextMenuPolicy(Qt.CustomContextMenu)

self.codeSumLabel = QLabel("found:")

self.codeSumLabel2 = QLabel("found:")

self.btn1 = QPushButton("Version Check")

#layout.addWidget(self.btn1)

self.btn2 = QPushButton('quit')

#self.btn2.clicked.connect(QApplication.instance().quit)

self.btn2.clicked.connect(self.myquit)

#layout.addWidget(self.btn2)

hbox = QHBoxLayout()

hbox.addStretch(1)

hbox.addWidget(self.codeSumLabel)

hbox.addWidget(self.codeSumLabel2)

hbox.addWidget(self.btn1)

hbox.addWidget(self.btn2)

layout.addStretch(0)

layout.addStretch(1)

layout.addLayout(hbox)

self.setLayout(layout)

self.resize(1100,650)

print(self.geometry())

以上是 PyQt5中布局内的控件如何充满布局? 的全部内容, 来源链接: utcz.com/a/157142.html

回到顶部