python - 如何在布局中组合列(colspan 功能)

标签 python qt layout pyqt pyqt5

我有这个代码:

#!/usr/bin/env python3

from PyQt5.QtWidgets import *
import sys    

class Window(QWidget):
    def __init__(self):
        QWidget.__init__(self)

        layout = QGridLayout()
        self.setLayout(layout)

        label_1 = QLabel("label 1")
        layout.addWidget(label_1, 0, 0)

        label_2 = QLabel("label 2")
        layout.addWidget(label_2, 0, 1)

        label_3 = QLabel("label 3")
        layout.addWidget(label_3, 1, 0)


app = QApplication(sys.argv)

screen = Window()
screen.show()

sys.exit(app.exec_())

我有这样的结果:

image example of current code

但我需要这个:

image example of code which I need

我该怎么做?

最佳答案

addWidget的第四个和第五个参数允许您指定要跨越的行数和列数:

label_3 = QLabel("label 3")
layout.addWidget(label_3, 1, 0, 1, 2)

关于python - 如何在布局中组合列(colspan 功能),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38325350/

相关文章:

c++ - 无法从 Qt C++ 将发出的信号捕捉到 QML 中

c++ - QListWidget 的高度与窗口的高度相同

layout - symfony2- Twig : Configure parent template from child?

wpf - 在 WrapPanel 中同步 WPF 控件宽度

python - 从 PDF python 中提取/识别表

python - 如何在 XPath 中使用 contains()?

python - 按一定的优先顺序将 pandas 列组合到新列中

Python Pandas - 在列中搜索值并附加到新列

c++ - QObject 作为域对象的基类。过度设计?

android - 在 onResume() 之前动态更改 DialogFragment Max_Height?