Вопрос по – QVBoxLayout: Как выровнять виджеты по вертикали вместо центра

34

В Qt, когда я добавляю виджеты в свой макет, они по умолчанию центрированы вертикально. Есть ли способ «Список»? виджеты сверху вниз вместо их центрирования по вертикали?

Ваш Ответ

4   ответа
34

void QLayout::setAlignment ( Qt::Alignment alignment )

10

Error: User Rate Limit ExceededQVBoxLayoutError: User Rate Limit Exceeded

layout.addStretch()

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded.

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
8

Error: User Rate Limit Exceeded

myLayout.setAlignment(Qt.AlignTop)

Error: User Rate Limit Exceeded

myLayout.setAlignment(myWidget, Qt.AlignTop)

Error: User Rate Limit Exceeded

20

layout.setAlignment()

notQTextBrowser()layout.setAlignment(Qt.AlignTop)

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class MyWidget(QWidget):
    """
    Create a widget that aligns its contents to the top.
    """

    def __init__(self, parent=None):

        QWidget.__init__(self, parent)

        layout = QVBoxLayout()

        label = QLabel('label:')
        layout.addWidget(label)

        info = QTextBrowser(self)
        info.setMinimumHeight(100)
        info.setMaximumHeight(200)
        layout.addWidget(info)        
        # Uncomment the next line to get this to align top.
#         layout.setAlignment(info, Qt.AlignTop)

        # Create a progress bar layout.
        button = QPushButton('Button 1')        
        layout.addWidget(button)        

        # This will align all the widgets to the top except
        # for the QTextBrowser() since it has a maximum size set.
        layout.setAlignment(Qt.AlignTop)

        self.setLayout(layout)


if __name__ == '__main__':

    import sys

    app = QApplication(sys.argv)

    widget = MyWidget()
    widget.show()
    widget.resize(QSize(900, 400))

    app.exec_()

layout.setAlignment(info, Qt.AlignTop)

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class MyWidget(QWidget):
    """
    Create a widget that aligns its contents to the top.
    """

    def __init__(self, parent=None):

        QWidget.__init__(self, parent)

        layout = QVBoxLayout()

        label = QLabel('label:')
        layout.addWidget(label)

        info = QTextBrowser(self)
        info.setMinimumHeight(100)
        info.setMaximumHeight(200)
        layout.addWidget(info)        
        # Uncomment the next line to get this to align top.
        layout.setAlignment(info, Qt.AlignTop)

        # Create a progress bar layout.
        button = QPushButton('Button 1')        
        layout.addWidget(button)        

        # This will align all the widgets to the top except
        # for the QTextBrowser() since it has a maximum size set.
        layout.setAlignment(Qt.AlignTop)

        self.setLayout(layout)


if __name__ == '__main__':

    import sys

    app = QApplication(sys.argv)

    widget = MyWidget()
    widget.show()
    widget.resize(QSize(900, 400))

    app.exec_()
Error: User Rate Limit ExceededwhyError: User Rate Limit Exceeded

Похожие вопросы